예제 #1
0
 /**
  * Add value to result
  *
  * @param int $storeId
  * @return $this
  */
 public function addValuesToResult($storeId = null)
 {
     if ($storeId === null) {
         $storeId = $this->_storeManager->getStore()->getId();
     }
     $optionIds = [];
     foreach ($this as $option) {
         $optionIds[] = $option->getId();
     }
     if (!empty($optionIds)) {
         /** @var \Magento\Catalog\Model\Resource\Product\Option\Value\Collection $values */
         $values = $this->_optionValueCollectionFactory->create();
         $values->addTitleToResult($storeId)->addPriceToResult($storeId)->addOptionToFilter($optionIds)->setOrder('sort_order', self::SORT_ORDER_ASC)->setOrder('title', self::SORT_ORDER_ASC);
         foreach ($values as $value) {
             $optionId = $value->getOptionId();
             if ($this->getItemById($optionId)) {
                 $this->getItemById($optionId)->addValue($value);
                 $value->setOption($this->getItemById($optionId));
             }
         }
     }
     return $this;
 }
예제 #2
0
 /**
  * @param array $optionIds
  * @param int $option_id
  * @param int $store_id
  * @return \Magento\Catalog\Model\Resource\Product\Option\Value\Collection
  */
 public function getValuesByOption($optionIds, $option_id, $store_id)
 {
     $collection = $this->_valueCollectionFactory->create()->addFieldToFilter('option_id', $option_id)->getValuesByOption($optionIds, $store_id);
     return $collection;
 }