コード例 #1
0
ファイル: Rss.php プロジェクト: kidaa30/magento2-platformsh
 /**
  * @return $this|\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  */
 public function getProductCollection()
 {
     /** @var $reviewModel \Magento\Review\Model\Review */
     $reviewModel = $this->reviewFactory->create();
     $collection = $reviewModel->getProductCollection()->addStatusFilter($reviewModel->getPendingStatus())->addAttributeToSelect('name', 'inner')->setDateOrder();
     $this->eventManager->dispatch('rss_catalog_review_collection_select', ['collection' => $collection]);
     return $collection;
 }
コード例 #2
0
ファイル: Product.php プロジェクト: Doability/magento2dev
 /**
  * {@inheritdoc}
  */
 public function setCollection($collection)
 {
     parent::setCollection($collection);
     $collection->addAttributeToSelect('short_description')->addAttributeToSelect('description');
     if ($this->config->isShowRating()) {
         $this->reviewFactory->create()->appendSummary($collection);
     }
     return $this;
 }
コード例 #3
0
ファイル: Observer.php プロジェクト: shabbirvividads/magento2
 /**
  * Append review summary before rendering html
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function catalogBlockProductCollectionBeforeToHtml(\Magento\Framework\Event\Observer $observer)
 {
     $productCollection = $observer->getEvent()->getCollection();
     if ($productCollection instanceof \Magento\Framework\Data\Collection) {
         $productCollection->load();
         $this->_reviewFactory->create()->appendSummary($productCollection);
     }
     return $this;
 }
コード例 #4
0
ファイル: View.php プロジェクト: shabbirvividads/magento2
 /**
  * Render review details
  *
  * @return void
  */
 public function execute()
 {
     $review = $this->reviewFactory->create()->load($this->getRequest()->getParam('id'));
     if ($review->getCustomerId() != $this->_customerSession->getCustomerId()) {
         return $this->_forward('noroute');
     }
     $this->_view->loadLayout();
     if ($navigationBlock = $this->_view->getLayout()->getBlock('customer_account_navigation')) {
         $navigationBlock->setActive('review/customer');
     }
     $this->_view->getPage()->getConfig()->getTitle()->set(__('Review Details'));
     $this->_view->renderLayout();
 }
コード例 #5
0
ファイル: Review.php プロジェクト: aiesh/magento2
 /**
  * Render XML response
  *
  * @return string
  */
 protected function _toHtml()
 {
     $newUrl = $this->getUrl('rss/catalog/review', array('_secure' => true, '_nosecret' => true));
     $title = __('Pending product review(s)');
     /** @var $rssObj \Magento\Rss\Model\Rss */
     $rssObj = $this->_rssFactory->create();
     $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'));
     /** @var $reviewModel \Magento\Review\Model\Review */
     $reviewModel = $this->_reviewFactory->create();
     $collection = $reviewModel->getProductCollection()->addStatusFilter($reviewModel->getPendingStatus())->addAttributeToSelect('name', 'inner')->setDateOrder();
     $this->_eventManager->dispatch('rss_catalog_review_collection_select', array('collection' => $collection));
     $this->_resourceIterator->walk($collection->getSelect(), array(array($this, 'addReviewItemXmlCallback')), array('rssObj' => $rssObj, 'reviewModel' => $reviewModel));
     return $rssObj->createRssXml();
 }
コード例 #6
0
ファイル: View.php プロジェクト: aiesh/magento2
 /**
  * Get product reviews summary
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param bool $templateType
  * @param bool $displayIfNoReviews
  * @return string
  */
 public function getReviewsSummaryHtml(\Magento\Catalog\Model\Product $product, $templateType = false, $displayIfNoReviews = false)
 {
     if (!$product->getRatingSummary()) {
         $this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId());
     }
     return parent::getReviewsSummaryHtml($product, $templateType, $displayIfNoReviews);
 }
コード例 #7
0
ファイル: Review.php プロジェクト: ktplKunj/TestMagento
 /**
  * @param array $row
  * @return \Magento\Review\Model\Review
  */
 protected function prepareReview($row)
 {
     /** @var $review \Magento\Review\Model\Review */
     $review = $this->reviewFactory->create();
     $review->setEntityId($review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE))->setEntityPkValue($this->getProductIdBySku($row['sku']))->setNickname($row['reviewer'])->setTitle($row['title'])->setDetail($row['review'])->setStatusId(\Magento\Review\Model\Review::STATUS_APPROVED)->setStoreId($this->storeManager->getStoreId())->setStores([$this->storeManager->getStoreId()]);
     return $review;
 }
コード例 #8
0
ファイル: Grid.php プロジェクト: shabbirvividads/magento2
 /**
  * Prepare collection
  *
  * @return \Magento\Review\Block\Adminhtml\Grid
  */
 protected function _prepareCollection()
 {
     /** @var $model \Magento\Review\Model\Review */
     $model = $this->_reviewFactory->create();
     /** @var $collection \Magento\Review\Model\Resource\Review\Product\Collection */
     $collection = $this->_productsFactory->create();
     if ($this->getProductId() || $this->getRequest()->getParam('productId', false)) {
         $productId = $this->getProductId();
         if (!$productId) {
             $productId = $this->getRequest()->getParam('productId');
         }
         $this->setProductId($productId);
         $collection->addEntityFilter($this->getProductId());
     }
     if ($this->getCustomerId() || $this->getRequest()->getParam('customerId', false)) {
         $customerId = $this->getCustomerId();
         if (!$customerId) {
             $customerId = $this->getRequest()->getParam('customerId');
         }
         $this->setCustomerId($customerId);
         $collection->addCustomerFilter($this->getCustomerId());
     }
     if ($this->_coreRegistry->registry('usePendingFilter') === true) {
         $collection->addStatusFilter($model->getPendingStatus());
     }
     $collection->addStoreData();
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
コード例 #9
0
 /**
  * Get review summary html
  *
  * @param Product $product
  * @param string $templateType
  * @param bool $displayIfNoReviews
  *
  * @return string
  */
 public function getReviewsSummaryHtml(\Magento\Catalog\Model\Product $product, $templateType = self::DEFAULT_VIEW, $displayIfNoReviews = false)
 {
     if (!$product->getRatingSummary() && !$displayIfNoReviews) {
         return '';
     }
     // pick template among available
     if (empty($this->_availableTemplates[$templateType])) {
         $templateType = self::DEFAULT_VIEW;
     }
     $this->setTemplate($this->_availableTemplates[$templateType]);
     $this->setDisplayIfEmpty($displayIfNoReviews);
     if (!$product->getRatingSummary()) {
         $this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId());
     }
     $this->setProduct($product);
     return $this->toHtml();
 }
コード例 #10
0
ファイル: View.php プロジェクト: kidaa30/magento2-platformsh
 /**
  * Render review details
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $review = $this->reviewFactory->create()->load($this->getRequest()->getParam('id'));
     if ($review->getCustomerId() != $this->customerSession->getCustomerId()) {
         /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
         $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
         $resultForward->forward('noroute');
         return $resultForward;
     }
     /** @var \Magento\Framework\View\Result\Page $resultPage */
     $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
     if ($navigationBlock = $resultPage->getLayout()->getBlock('customer_account_navigation')) {
         $navigationBlock->setActive('review/customer');
     }
     $resultPage->getConfig()->getTitle()->set(__('Review Details'));
     return $resultPage;
 }
コード例 #11
0
 /**
  * @return int
  */
 protected function getReviewEntityId()
 {
     if (!$this->reviewProductEntityId) {
         /** @var $review \Magento\Review\Model\Review */
         $review = $this->reviewFactory->create();
         $this->reviewProductEntityId = $review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE);
     }
     return $this->reviewProductEntityId;
 }
コード例 #12
0
ファイル: PostTest.php プロジェクト: nblair/magescotch
    /**
     * Check postAction method and assert that review model storeId equals null.
     */
    public function testPostAction()
    {
        $this->requestMock->expects($this->any())
            ->method('getParam')
            ->willReturnMap(
                [
                    ['product_id', false, 1],
                    ['ratings', [], ['1' => '1']]
                ]
            );
        $this->requestMock->expects($this->once())
            ->method('getPostValue')
            ->willReturn(['status_id' => 1]);
        $this->objectManagerMock->expects($this->any())
            ->method('get')
            ->with('Magento\Store\Model\StoreManagerInterface')
            ->willReturn($this->storeManagerMock);
        $this->reviewFactoryMock->expects($this->once())
            ->method('create')
            ->willReturn($this->reviewMock);
        $this->ratingFactoryMock->expects($this->once())
            ->method('create')
            ->willReturn($this->ratingMock);
        $this->storeManagerMock->expects($this->once())
            ->method('hasSingleStore')
            ->willReturn(true);
        $this->storeManagerMock->expects($this->once())
            ->method('getStore')
            ->willReturn($this->storeModelMock);
        $this->storeModelMock->expects($this->once())
            ->method('getId')
            ->willReturn(1);
        $this->reviewMock->expects($this->once())
            ->method('save')
            ->willReturn($this->reviewMock);
        $this->reviewMock->expects($this->once())
            ->method('getId')
            ->willReturn(1);
        $this->reviewMock->expects($this->once())
            ->method('aggregate')
            ->willReturn($this->reviewMock);
        $this->ratingMock->expects($this->once())
            ->method('setRatingId')
            ->willReturnSelf();
        $this->ratingMock->expects($this->once())
            ->method('setReviewId')
            ->willReturnSelf();
        $this->ratingMock->expects($this->once())
            ->method('addOptionVote')
            ->willReturnSelf();

        $this->assertSame($this->resultRedirectMock, $this->postController->executeInternal());
    }
コード例 #13
0
 /**
  * Filter items for review. If a customer has already placed a review for a product then exclude the product.
  *
  * @param array $items
  * @param int   $websiteId
  *
  * @return mixed
  */
 public function filterItemsForReview($items, $websiteId)
 {
     $order = $this->getOrder();
     if (empty($items) || !$order) {
         return false;
     }
     //if customer is guest then no need to filter any items
     if ($order->getCustomerIsGuest()) {
         return $items;
     }
     if (!$this->helper->isNewProductOnly($websiteId)) {
         return $items;
     }
     $customerId = $order->getCustomerId();
     foreach ($items as $key => $item) {
         $productId = $item->getProduct()->getId();
         $collection = $this->reviewFactory->create()->getCollection()->addCustomerFilter($customerId)->addStoreFilter($order->getStoreId())->addFieldToFilter('main_table.entity_pk_value', $productId);
         //remove item if customer has already placed review on this item
         if ($collection->getSize()) {
             unset($items[$key]);
         }
     }
     return $items;
 }
コード例 #14
0
 /**
  * Initialize product review
  *
  * @param \Magento\Catalog\Block\Product\Compare\ListCompare $subject
  * @param \Magento\Catalog\Model\Product $product
  * @param bool $templateType
  * @param bool $displayIfNoReviews
  *
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeGetReviewsSummaryHtml(\Magento\Catalog\Block\Product\Compare\ListCompare $subject, \Magento\Catalog\Model\Product $product, $templateType = false, $displayIfNoReviews = false)
 {
     if (!$product->getRatingSummary()) {
         $this->reviewFactory->create()->getEntitySummary($product, $this->storeManager->getStore()->getId());
     }
 }
コード例 #15
0
ファイル: Edit.php プロジェクト: pradeep-wagento/magento2
 /**
  * Initialize edit review
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _construct()
 {
     parent::_construct();
     $this->_objectId = 'id';
     $this->_blockGroup = 'Magento_Review';
     $this->_controller = 'adminhtml';
     /** @var $actionPager \Magento\Review\Helper\Action\Pager */
     $actionPager = $this->_reviewActionPager;
     $actionPager->setStorageId('reviews');
     $reviewId = $this->getRequest()->getParam('id');
     $prevId = $actionPager->getPreviousItemId($reviewId);
     $nextId = $actionPager->getNextItemId($reviewId);
     if ($prevId !== false) {
         $this->addButton('previous', ['label' => __('Previous'), 'onclick' => 'setLocation(\'' . $this->getUrl('review/*/*', ['id' => $prevId]) . '\')'], 3, 10);
         $this->addButton('save_and_previous', ['label' => __('Save and Previous'), 'class' => 'save', 'data_attribute' => ['mage-init' => ['button' => ['event' => 'save', 'target' => '#edit_form', 'eventData' => ['action' => ['args' => ['next_item' => $prevId]]]]]]], 3, 11);
     }
     if ($nextId !== false) {
         $this->addButton('save_and_next', ['label' => __('Save and Next'), 'class' => 'save', 'data_attribute' => ['mage-init' => ['button' => ['event' => 'save', 'target' => '#edit_form', 'eventData' => ['action' => ['args' => ['next_item' => $nextId]]]]]]], 3, 100);
         $this->addButton('next', ['label' => __('Next'), 'onclick' => 'setLocation(\'' . $this->getUrl('review/*/*', ['id' => $nextId]) . '\')'], 3, 105);
     }
     $this->buttonList->update('save', 'label', __('Save Review'));
     $this->buttonList->update('save', 'id', 'save_button');
     $this->buttonList->update('delete', 'label', __('Delete Review'));
     if ($this->getRequest()->getParam('productId', false)) {
         $this->buttonList->update('back', 'onclick', 'setLocation(\'' . $this->getUrl('catalog/product/edit', ['id' => $this->getRequest()->getParam('productId', false)]) . '\')');
     }
     if ($this->getRequest()->getParam('customerId', false)) {
         $this->buttonList->update('back', 'onclick', 'setLocation(\'' . $this->getUrl('customer/index/edit', ['id' => $this->getRequest()->getParam('customerId', false)]) . '\')');
     }
     if ($this->getRequest()->getParam('ret', false) == 'pending') {
         $this->buttonList->update('back', 'onclick', 'setLocation(\'' . $this->getUrl('catalog/*/pending') . '\')');
         $this->buttonList->update('delete', 'onclick', 'deleteConfirm(' . '\'' . __('Are you sure you want to do this?') . '\' ' . '\'' . $this->getUrl('*/*/delete', [$this->_objectId => $this->getRequest()->getParam($this->_objectId), 'ret' => 'pending']) . '\'' . ')');
         $this->_coreRegistry->register('ret', 'pending');
     }
     if ($this->getRequest()->getParam($this->_objectId)) {
         $reviewData = $this->_reviewFactory->create()->load($this->getRequest()->getParam($this->_objectId));
         $this->_coreRegistry->register('review_data', $reviewData);
     }
     $this->_formInitScripts[] = '
         var review = {
             updateRating: function() {
                     elements = [
                         $("select_stores"),
                         $("rating_detail").getElementsBySelector("input[type=\'radio\']")
                     ].flatten();
                     $(\'save_button\').disabled = true;
                     new Ajax.Updater(
                         "rating_detail",
                         "' . $this->getUrl('review/*/ratingItems', ['_current' => true]) . '",
                         {
                             parameters:Form.serializeElements(elements),
                             evalScripts:true,
                             onComplete:function(){ $(\'save_button\').disabled = false; }
                         }
                     );
                 }
        }
        Event.observe(window, \'load\', function(){
              Event.observe($("select_stores"), \'change\', review.updateRating);
        });
     ';
 }
 /**
  * Add review summary info for tagged product collection
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $collection = $observer->getEvent()->getCollection();
     $this->_reviewFactory->create()->appendSummary($collection);
     return $this;
 }