Exemple #1
0
 /**
  * @param int[] $productIds
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function getCustomOptionsData($productIds)
 {
     $customOptionsData = [];
     foreach (array_keys($this->_storeIdToCode) as $storeId) {
         if (Store::DEFAULT_STORE_ID != $storeId) {
             continue;
         }
         $options = $this->_optionColFactory->create();
         /* @var \Magento\Catalog\Model\ResourceModel\Product\Option\Collection $options*/
         $options->addOrder('sort_order');
         $options->reset()->addOrder('sort_order')->addTitleToResult($storeId)->addPriceToResult($storeId)->addProductToFilter($productIds)->addValuesToResult($storeId);
         foreach ($options as $option) {
             $row = [];
             $productId = $option['product_id'];
             $row['name'] = $option['title'];
             $row['type'] = $option['type'];
             $row['required'] = $option['is_require'];
             $row['price'] = $option['price'];
             $row['price_type'] = $option['price_type'] == 'percent' ? $option['price_type'] : 'fixed';
             $row['sku'] = $option['sku'];
             if ($option['max_characters']) {
                 $row['max_characters'] = $option['max_characters'];
             }
             $values = $option->getValues();
             if ($values) {
                 foreach ($values as $value) {
                     $valuePriceType = $value['price_type'] == 'percent' ? $value['price_type'] : 'fixed';
                     $row['option_title'] = $value['title'];
                     $row['price'] = $value['price'];
                     $row['price_type'] = $valuePriceType;
                     $row['sku'] = $value['sku'];
                     $customOptionsData[$productId][$storeId][] = $this->optionRowToCellString($row);
                 }
             } else {
                 $customOptionsData[$productId][$storeId][] = $this->optionRowToCellString($row);
             }
             $option = null;
         }
         $options = null;
     }
     return $customOptionsData;
 }
 /**
  *  Returns actual product data: current id, options, options data and option values
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Option\Collection $options
  * @return array
  */
 protected function getActualOptionsData(\Magento\Catalog\Model\ResourceModel\Product\Option\Collection $options)
 {
     $actualOptionId = 0;
     $actualOptions = [];
     // array of type and title types, key is element ID
     $actualData = [];
     // array of option data
     $actualValues = [];
     // array of option values data
     /** @var $option \Magento\Catalog\Model\Product\Option */
     foreach ($options->getItems() as $option) {
         $lastOptionKey = $option->getType() . '|' . $option->getTitle();
         $actualOptionId++;
         if (!in_array($lastOptionKey, $actualOptions)) {
             $actualOptions[$actualOptionId] = $lastOptionKey;
             $actualData[$actualOptionId] = $this->getOptionData($option);
             if ($optionValues = $this->getOptionValues($option)) {
                 $actualValues[$actualOptionId] = $optionValues;
             }
         }
     }
     return ['id' => $actualOptionId, 'options' => $actualOptions, 'data' => $actualData, 'values' => $actualValues];
 }
Exemple #3
0
 public function testReset()
 {
     $this->collection->reset();
 }
Exemple #4
0
 /**
  * Load exiting custom options data
  *
  * @return $this
  */
 protected function _initOldCustomOptions()
 {
     if (!$this->_oldCustomOptions) {
         $oldCustomOptions = [];
         $optionTitleTable = $this->_tables['catalog_product_option_title'];
         foreach ($this->_storeCodeToId as $storeId) {
             $addCustomOptions = function (\Magento\Catalog\Model\Product\Option $customOption) use(&$oldCustomOptions, $storeId) {
                 $productId = $customOption->getProductId();
                 if (!isset($oldCustomOptions[$productId])) {
                     $oldCustomOptions[$productId] = [];
                 }
                 if (isset($oldCustomOptions[$productId][$customOption->getId()])) {
                     $oldCustomOptions[$productId][$customOption->getId()]['titles'][$storeId] = $customOption->getTitle();
                 } else {
                     $oldCustomOptions[$productId][$customOption->getId()] = ['titles' => [$storeId => $customOption->getTitle()], 'type' => $customOption->getType()];
                 }
             };
             /** @var $collection \Magento\Catalog\Model\ResourceModel\Product\Option\Collection */
             $this->_optionCollection->reset();
             $this->_optionCollection->getSelect()->join(['option_title' => $optionTitleTable], 'option_title.option_id = main_table.option_id', ['title' => 'title', 'store_id' => 'store_id'])->where('option_title.store_id = ?', $storeId);
             $this->_byPagesIterator->iterate($this->_optionCollection, $this->_pageSize, [$addCustomOptions]);
         }
         $this->_oldCustomOptions = $oldCustomOptions;
     }
     return $this;
 }