/** * 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; }