Ejemplo n.º 1
0
 /**
  * @param int $productId
  * @param \Magento\Review\Model\ResourceModel\Review\Collection $reviewsCollection
  * @return \Magento\Review\Model\Review[]
  */
 public function getReviewsWithPurchaseDate($productId, $reviewsCollection)
 {
     $customersWithPurchaseDate = $this->resource->getCustomersWithWithPurchaseDate($productId, $this->getCustomerList($reviewsCollection));
     /** @var \Magento\Review\Model\Review $review */
     foreach ($reviewsCollection as $review) {
         if (isset($customersWithPurchaseDate[$review->getData('customer_id')])) {
             $review->setData('purchase_date', $customersWithPurchaseDate[$review->getData('customer_id')]);
         }
     }
     return $reviewsCollection;
 }
Ejemplo n.º 2
0
 public function testGetCustomersWithWithPurchaseDate()
 {
     $productId = 12;
     $customerIds = [4, 6, 9];
     $result = [4 => 'date 4', 6 => 'date 6', 9 => 'date 9'];
     $customerOrderItems = [$this->createOrderItem(4, 'date 4'), $this->createOrderItem(6, 'date 6'), $this->createOrderItem(9, 'date 9')];
     $this->orderItemCollection->expects($this->once())->method('join')->with(['order' => 'sales_order'], 'main_table.order_id = order.entity_id', ['customer_id' => 'customer_id', 'purchase_date' => 'order.updated_at'])->willReturnSelf();
     $this->orderItemCollection->expects($this->exactly(3))->method('addFieldToFilter')->withConsecutive(['main_table.product_id', $productId], ['order.status', 'complete'], ['order.customer_id', ['in' => $customerIds]])->willReturnSelf();
     $this->orderItemCollection->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator($customerOrderItems));
     $this->assertEquals($result, $this->buyer->getCustomersWithWithPurchaseDate($productId, $customerIds));
 }