/**
  * {@inheritdoc}
  */
 public function getData()
 {
     if (!$this->getCollection()->isLoaded()) {
         $currentProductId = (int) $this->request->getParam('current_product_id');
         if (0 !== $currentProductId) {
             $this->getCollection()->getSelect()->where('e.entity_id != ?', $currentProductId);
         }
         $this->getCollection()->getSelect()->distinct()->join(['opt' => $this->getCollection()->getTable('catalog_product_option')], 'opt.product_id = e.entity_id', null);
         $this->getCollection()->load();
         /** @var ProductInterface $product */
         foreach ($this->getCollection() as $product) {
             $options = [];
             /** @var ProductOption|DataObject $option */
             foreach ($this->productOptionRepository->getProductOptions($product) as $option) {
                 $option->setData('values', $this->productOptionValueModel->getValuesCollection($option)->toArray()['items']);
                 $options[] = $option->toArray();
             }
             $product->setOptions($options);
         }
     }
     $items = $this->getCollection()->toArray();
     return ['totalRecords' => $this->getCollection()->getSize(), 'items' => array_values($items)];
 }
Exemplo n.º 2
0
 public function testGetValuesCollection()
 {
     $this->assertInstanceOf('\\Magento\\Catalog\\Model\\Resource\\Product\\Option\\Value\\Collection', $this->model->getValuesCollection($this->getMockedOption()));
 }