Beispiel #1
0
 /**
  * @depends testItems
  */
 public function testOptions($attributeId)
 {
     if (!$attributeId) {
         $this->fail('Wromg attribute id');
     }
     $options = $this->_model->options($attributeId);
     $this->assertInternalType('array', $options);
     $element = current($options);
     $this->assertArrayHasKey('value', $element);
     $this->assertArrayHasKey('label', $element);
 }
 /**
  * Create new product attribute
  *
  * @param array $data input data
  * @return integer
  */
 public function create($data)
 {
     // if frontend_label is not provided as an array, help the client
     if (!empty($data['frontend_label']) && !is_array($data['frontend_label'])) {
         $frontend_label = $data['frontend_label'];
         $data['frontend_label'] = array(array('store_id' => 0, 'label' => $frontend_label));
     }
     return parent::create($data);
 }
Beispiel #3
0
 /**
  * Get full information about attribute with list of options
  *
  * @param integer|string $attribute attribute ID or code
  * @return array
  */
 public function info($attribute)
 {
     $result = parent::info($attribute);
     if (!empty($result['additional_fields'])) {
         $keys = array_keys($result['additional_fields']);
         foreach ($keys as $key) {
             $result['additional_fields'][] = array('key' => $key, 'value' => $result['additional_fields'][$key]);
             unset($result['additional_fields'][$key]);
         }
     }
     return $result;
 }
Beispiel #4
0
 /**
  * Add option to select or multiselect attribute
  *
  * @param  integer|string $attribute attribute ID or code
  * @param  array $data
  * @return integer
  */
 public function addOption($attribute, $data)
 {
     $parent = parent::addOption($attribute, $data);
     if ($parent) {
         $model = $this->_getAttribute($attribute);
         /** @var $helperCatalog Mage_Catalog_Helper_Data */
         $helperCatalog = Mage::helper('catalog');
         foreach ($data['label'] as $label) {
             $labelText = $helperCatalog->stripTags($label['value']);
         }
         $code = $model->getAttributeCode();
         $_product = Mage::getModel('catalog/product');
         $attr = $_product->getResource()->getAttribute($code);
         if ($attr->usesSource()) {
             $option_id = $attr->getSource()->getOptionId($labelText);
         }
         return $option_id;
     }
     return $parent;
 }