コード例 #1
0
 /**
  * Create configurable product options
  *
  * @param array $attributesData
  * @return OptionInterface[]
  * @throws \InvalidArgumentException
  */
 public function create(array $attributesData)
 {
     $options = [];
     foreach ($attributesData as $item) {
         $attribute = $this->attributeFactory->create();
         $eavAttribute = $this->productAttributeRepository->get($item[Attribute::KEY_ATTRIBUTE_ID]);
         if (!$this->productType->canUseAttribute($eavAttribute)) {
             throw new \InvalidArgumentException('Provided attribute can not be used with configurable product.');
         }
         $this->updateAttributeData($attribute, $item);
         $options[] = $attribute;
     }
     return $options;
 }
コード例 #2
0
 /**
  * Prepare form before rendering HTML
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $fieldset = $form->addFieldset('settings', ['legend' => __('Select Configurable Attributes')]);
     $fieldset->addField('configurable-attribute-selector', 'text', ['label' => 'Select Attribute', 'title' => 'Select Attribute']);
     $product = $this->getProduct();
     $usedAttributes = $product->getTypeId() == Configurable::TYPE_CODE ? $this->_configurableType->getUsedProductAttributes($product) : [];
     foreach ($usedAttributes as $attribute) {
         /** @var $attribute \Magento\Catalog\Model\Resource\Eav\Attribute */
         if ($this->_configurableType->canUseAttribute($attribute, $product)) {
             $fieldset->addField('attribute_' . $attribute->getAttributeId(), 'checkbox', ['label' => $attribute->getFrontendLabel(), 'title' => $attribute->getFrontendLabel(), 'name' => 'attributes[]', 'class' => 'configurable-attribute-checkbox', 'value' => $attribute->getAttributeId(), 'checked' => true]);
         }
     }
     $fieldset->addField('continue_button', 'note', ['text' => $this->getChildHtml('continue_button')]);
     $this->setForm($form);
     return parent::_prepareForm();
 }
コード例 #3
0
ファイル: ConfigurableTest.php プロジェクト: nja78/magento2
 public function testCanUseAttribute()
 {
     $attribute = $this->getMock('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute', ['getIsGlobal', 'getIsVisible', 'usesSource', 'getIsUserDefined', '__wakeup', '__sleep'], [], '', false);
     $attribute->expects($this->once())->method('getIsGlobal')->will($this->returnValue(1));
     $attribute->expects($this->once())->method('getIsVisible')->will($this->returnValue(1));
     $attribute->expects($this->once())->method('usesSource')->will($this->returnValue(1));
     $attribute->expects($this->once())->method('getIsUserDefined')->will($this->returnValue(1));
     $this->assertTrue($this->_model->canUseAttribute($attribute));
 }
コード例 #4
0
ファイル: ConfigurableTest.php プロジェクト: nja78/magento2
 public function testCanUseAttribute()
 {
     $this->assertFalse($this->_model->canUseAttribute($this->_getAttributeByCode('sku')));
     $this->assertTrue($this->_model->canUseAttribute($this->_getAttributeByCode('test_configurable')));
 }