/** * Get data * * @return array */ public function getData() { if (!$this->getCollection()->isLoaded()) { $this->getCollection()->addAttributeToFilter('type_id', $this->config->getComposableTypes()); if ($storeId = $this->request->getParam('current_store_id')) { /** @var StoreInterface $store */ $store = $this->storeRepository->getById($storeId); $this->getCollection()->setStore($store); } $this->getCollection()->load(); } $items = $this->getCollection()->toArray(); return ['totalRecords' => $this->getCollection()->getSize(), 'items' => array_values($items)]; }
/** * Add attributes to select * * @return $this */ public function _initSelect() { parent::_initSelect(); $allowedProductTypes = $this->_productTypeConfig->getComposableTypes(); $this->addAttributeToSelect('name')->addAttributeToSelect('price')->addAttributeToSelect('sku')->addAttributeToSelect('weight')->addAttributeToSelect('image')->addFieldToFilter('type_id', $allowedProductTypes)->addFieldToFilter('entity_id', array('neq' => $this->getProduct()->getId()))->addFilterByRequiredOptions()->joinAttribute('name', 'catalog_product/name', 'entity_id', null, 'inner')->joinTable(array('cisi' => 'cataloginventory_stock_item'), 'product_id=entity_id', array('qty' => 'qty', 'inventory_in_stock' => 'is_in_stock'), null, 'left'); return $this; }
/** * @inheritdoc */ public function _initSelect() { parent::_initSelect(); $this->setProduct($this->_getProduct())->addAttributeToSelect('name')->addAttributeToSelect('price')->addAttributeToSelect('sku')->addFilterByRequiredOptions()->addAttributeToFilter('type_id', $this->_config->getComposableTypes()); return $this; }
/** * Array of SKU to array of super attribute values for all products. * * @param array $bunch - portion of products to process * @param array $newSku - imported variations list * @param array $oldSku - present variations list * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _loadSkuSuperAttributeValues($bunch, $newSku, $oldSku) { if ($this->_superAttributes) { $attrSetIdToName = $this->_entityModel->getAttrSetIdToName(); $productIds = []; foreach ($bunch as $rowData) { $dataWithExtraVirtualRows = $this->_parseVariations($rowData); if (!empty($dataWithExtraVirtualRows)) { array_unshift($dataWithExtraVirtualRows, $rowData); } else { $dataWithExtraVirtualRows[] = $rowData; } foreach ($dataWithExtraVirtualRows as $data) { if (!empty($data['_super_products_sku'])) { if (isset($newSku[$data['_super_products_sku']])) { $productIds[] = $newSku[$data['_super_products_sku']]['entity_id']; } elseif (isset($oldSku[$data['_super_products_sku']])) { $productIds[] = $oldSku[$data['_super_products_sku']]['entity_id']; } } } } foreach ($this->_productColFac->create()->addFieldToFilter('type_id', $this->_productTypesConfig->getComposableTypes())->addFieldToFilter('entity_id', ['in' => $productIds])->addAttributeToSelect(array_keys($this->_superAttributes)) as $product) { $attrSetName = $attrSetIdToName[$product->getAttributeSetId()]; $data = array_intersect_key($product->getData(), $this->_superAttributes); foreach ($data as $attrCode => $value) { $attrId = $this->_superAttributes[$attrCode]['id']; $this->_skuSuperAttributeValues[$attrSetName][$product->getId()][$attrId] = $value; } } } return $this; }