Ejemplo n.º 1
0
 /**
  * Retrieve Option values array by ids
  *
  * @param string|array $ids
  * @param bool $withEmpty Add empty option to array
  * @return array
  */
 public function getSpecificOptions($ids, $withEmpty = true)
 {
     $options = $this->_attrOptionCollectionFactory->create()->setPositionOrder('asc')->setAttributeFilter($this->getAttribute()->getId())->addFieldToFilter('main_table.option_id', ['in' => $ids])->setStoreFilter($this->getAttribute()->getStoreId())->load()->toOptionArray();
     if ($withEmpty) {
         array_unshift($options, ['label' => '', 'value' => '']);
     }
     return $options;
 }
Ejemplo n.º 2
0
 /**
  * Retrieve Full Option values array
  *
  * @param bool $withEmpty       Add empty option to array
  * @param bool $defaultValues
  * @return array
  */
 public function getAllOptions($withEmpty = true, $defaultValues = false)
 {
     $storeId = $this->getAttribute()->getStoreId();
     if (!is_array($this->_options)) {
         $this->_options = array();
     }
     if (!is_array($this->_optionsDefault)) {
         $this->_optionsDefault = array();
     }
     if (!isset($this->_options[$storeId])) {
         $collection = $this->_attrOptionCollectionFactory->create()->setPositionOrder('asc')->setAttributeFilter($this->getAttribute()->getId())->setStoreFilter($this->getAttribute()->getStoreId())->load();
         $this->_options[$storeId] = $collection->toOptionArray();
         $this->_optionsDefault[$storeId] = $collection->toOptionArray('default_value');
     }
     $options = $defaultValues ? $this->_optionsDefault[$storeId] : $this->_options[$storeId];
     if ($withEmpty) {
         array_unshift($options, array('label' => '', 'value' => ''));
     }
     return $options;
 }
Ejemplo n.º 3
0
 /**
  * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute
  * @param array $data
  * @return array
  */
 protected function getOption($attribute, $data)
 {
     $result = [];
     $data['option'] = explode("\n", $data['option']);
     /** @var \Magento\Eav\Model\Resource\Entity\Attribute\Option\Collection $options */
     $options = $this->attrOptionCollectionFactory->create()->setAttributeFilter($attribute->getId())->setPositionOrder('asc', true)->load();
     foreach ($data['option'] as $value) {
         if (!$options->getItemByColumnValue('value', $value)) {
             $result[] = $value;
         }
     }
     return $result ? $this->convertOption($result) : $result;
 }
Ejemplo n.º 4
0
 /**
  * Retrieve attribute option values for given store id
  *
  * @param int $storeId
  * @return array
  */
 public function getStoreOptionValues($storeId)
 {
     $values = $this->getData('store_option_values_' . $storeId);
     if ($values === null) {
         $values = [];
         $valuesCollection = $this->_attrOptionCollectionFactory->create()->setAttributeFilter($this->getAttributeObject()->getId())->setStoreFilter($storeId, false)->load();
         foreach ($valuesCollection as $item) {
             $values[$item->getId()] = $item->getValue();
         }
         $this->setData('store_option_values_' . $storeId, $values);
     }
     return $values;
 }
Ejemplo n.º 5
0
 /**
  * Loads all attributes with options for attribute
  *
  * @param string $attributeCode
  * @return $this
  */
 protected function loadAttributeOptions($attributeCode)
 {
     /** @var \Magento\Catalog\Model\Resource\Product\Attribute\Collection $collection */
     $collection = $this->attributeCollectionFactory->create();
     $collection->addFieldToSelect(['attribute_code', 'attribute_id']);
     $collection->addFieldToFilter('attribute_code', $attributeCode);
     $collection->setFrontendInputTypeFilter(['in' => ['select', 'multiselect']]);
     foreach ($collection as $item) {
         $options = $this->attrOptionCollectionFactory->create()->setAttributeFilter($item->getAttributeId())->setPositionOrder('asc', true)->load();
         $this->attributeCodeOptionsPair[$item->getAttributeCode()] = $options;
     }
     return $this;
 }