コード例 #1
0
ファイル: Recent.php プロジェクト: nja78/magento2
 /**
  * Return collection of reviews
  *
  * @return array|\Magento\Review\Model\Resource\Review\Product\Collection
  */
 public function getReviews()
 {
     if (!($customerId = $this->currentCustomer->getCustomerId())) {
         return [];
     }
     if (!$this->_collection) {
         $this->_collection = $this->_collectionFactory->create();
         $this->_collection->addStoreFilter($this->_storeManager->getStore()->getId())->addCustomerFilter($customerId)->setDateOrder()->setPageSize(5)->load()->addReviewSummary();
     }
     return $this->_collection;
 }
コード例 #2
0
 /**
  * @dataProvider addAttributeToFilterWithAttributeTypeDataProvider
  * @param $condition
  * @param $sqlConditionWith
  * @param $sqlConditionWithSec
  * @param $doubleConditionSqlQuery
  */
 public function testAddAttributeToFilterWithAttributeType($condition, $sqlConditionWith, $sqlConditionWithSec, $doubleConditionSqlQuery)
 {
     $conditionSqlQuery = 'sqlQuery';
     $this->readAdapter->expects($this->at(0))->method('prepareSqlCondition')->with('rdt.customer_id', $sqlConditionWith)->will($this->returnValue($conditionSqlQuery));
     if ($sqlConditionWithSec) {
         $this->readAdapter->expects($this->at(1))->method('prepareSqlCondition')->with('rdt.store_id', $sqlConditionWithSec)->will($this->returnValue($conditionSqlQuery));
     }
     $conditionSqlQuery = $doubleConditionSqlQuery ? $conditionSqlQuery . ' AND ' . $conditionSqlQuery : $conditionSqlQuery;
     $this->dbSelect->expects($this->once())->method('where')->with($conditionSqlQuery)->will($this->returnSelf());
     $this->model->addAttributeToFilter('type', $condition);
 }
コード例 #3
0
 public function testGetCollection()
 {
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue(new \Magento\Framework\Object(array('id' => 42))));
     $this->currentCustomer->expects($this->any())->method('getCustomerId')->will($this->returnValue(4242));
     $this->collection->expects($this->any())->method('addStoreFilter')->with(42)->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('addCustomerFilter')->with(4242)->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('setDateOrder')->with()->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('setPageSize')->with(5)->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('load')->with()->will($this->returnValue($this->collection));
     $this->collection->expects($this->any())->method('addReviewSummary')->with()->will($this->returnValue($this->collection));
     $this->assertSame($this->collection, $this->object->getCollection());
 }
コード例 #4
0
ファイル: Review.php プロジェクト: kid17/magento2
 /**
  * Append review summary to product collection
  *
  * @param ProductCollection $collection
  * @return $this
  */
 public function appendSummary($collection)
 {
     $entityIds = [];
     foreach ($collection->getItems() as $item) {
         $entityIds[] = $item->getEntityId();
     }
     if (sizeof($entityIds) == 0) {
         return $this;
     }
     $summaryData = $this->_summaryFactory->create()->addEntityFilter($entityIds)->addStoreFilter($this->_storeManager->getStore()->getId())->load();
     foreach ($collection->getItems() as $item) {
         foreach ($summaryData as $summary) {
             if ($summary->getEntityPkValue() == $item->getEntityId()) {
                 $item->setRatingSummary($summary);
             }
         }
     }
     return $this;
 }
コード例 #5
0
ファイル: ListCustomer.php プロジェクト: aiesh/magento2
 /**
  * Initialize review collection
  *
  * @return $this
  */
 protected function _initCollection()
 {
     $this->_collection = $this->_collectionFactory->create();
     $this->_collection->addStoreFilter($this->_storeManager->getStore()->getId())->addCustomerFilter($this->currentCustomer->getCustomerId())->setDateOrder();
     return $this;
 }