コード例 #1
0
ファイル: ConfigurableTest.php プロジェクト: nja78/magento2
 public function testGetUsedProductAttributes()
 {
     $testConfigurable = $this->_getAttributeByCode('test_configurable');
     $attributeId = (int) $testConfigurable->getId();
     $attributes = $this->_model->getUsedProductAttributes($this->_product);
     $this->assertArrayHasKey($attributeId, $attributes);
     $this->assertSame($testConfigurable, $attributes[$attributeId]);
 }
コード例 #2
0
ファイル: ColumnSet.php プロジェクト: aiesh/magento2
 /**
  * Preparing layout
  *
  * @return \Magento\ConfigurableProduct\Block\Product\Configurable\AssociatedSelector\Backend\Grid\ColumnSet
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     $product = $this->getProduct();
     $attributes = $this->_productType->getUsedProductAttributes($product);
     foreach ($attributes as $attribute) {
         /** @var $attribute \Magento\Catalog\Model\Entity\Attribute */
         /** @var $block \Magento\Backend\Block\Widget\Grid\Column */
         $block = $this->addChild($attribute->getAttributeCode(), 'Magento\\Backend\\Block\\Widget\\Grid\\Column', array('header' => $attribute->getStoreLabel(), 'index' => $attribute->getAttributeCode(), 'type' => 'options', 'options' => $this->getOptions($attribute->getSource()), 'sortable' => false));
         $block->setId($attribute->getAttributeCode())->setGrid($this);
     }
     return $this;
 }
コード例 #3
0
 /**
  * Prepare attribute set comprising all selected configurable attributes
  *
  * @param \Magento\Catalog\Model\Product $product
  *
  * @return void
  */
 protected function prepareAttributeSetToBeBaseForNewVariations(\Magento\Catalog\Model\Product $product)
 {
     $attributes = $this->configurableProduct->getUsedProductAttributes($product);
     $attributeSetId = $product->getNewVariationsAttributeSetId();
     /** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */
     $attributeSet = $this->attributeSetFactory->create()->load($attributeSetId);
     $attributeSet->addSetInfo($this->entityFactory->create()->setType(\Magento\Catalog\Model\Product::ENTITY)->getTypeId(), $attributes);
     foreach ($attributes as $attribute) {
         /* @var $attribute \Magento\Catalog\Model\Entity\Attribute */
         if (!$attribute->isInSet($attributeSetId)) {
             $attribute->setAttributeSetId($attributeSetId)->setAttributeGroupId($attributeSet->getDefaultGroupId($attributeSetId))->save();
         }
     }
 }
 private function validateConfigurable($product, $attributeSetId, $storeId)
 {
     $type = $product->getTypeInstance();
     //var_dump(\Magento\Store\Model\ScopeInterface::SCOPE_STORE);die();
     $auto = $this->scopeConfig->getValue('catalog/configurable_value/auto_create', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if (!$type instanceof Configurable) {
         return true;
     }
     $attributeSet = $this->attributeSetFactory->create()->load($attributeSetId);
     $attributes = $this->configurableProduct->getUsedProductAttributes($product);
     $attributeSet->addSetInfo($this->entityFactory->create()->setType(\Magento\Catalog\Model\Product::ENTITY)->getTypeId(), $attributes);
     foreach ($type->getConfigurableAttributes($product) as $configAattribute) {
         $attribute = $configAattribute->getProductAttribute();
         if (!is_null($attribute)) {
             //var_dump($attribute->isInSet($attributeSetId));die();
             if (!$attribute->isInSet($attributeSetId)) {
                 if ($auto) {
                     $attribute->setAttributeSetId($attributeSetId)->setAttributeGroupId($attributeSet->getDefaultGroupId($attributeSetId))->save();
                     return true;
                 } else {
                     $this->messageManager->addError(__('The configurable attribute ' . $attribute->getAttributeCode() . ' is not available in the targeted attribute set. Please create it first! Or allow create it from global config Catalog->Change Attribte Set'));
                     return false;
                 }
             } else {
                 return true;
             }
         }
     }
 }
コード例 #5
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();
 }
コード例 #6
0
ファイル: Matrix.php プロジェクト: nja78/magento2
 /**
  * Get used product attributes
  *
  * @return array
  */
 public function getUsedAttributes()
 {
     return $this->_configurableType->getUsedProductAttributes($this->getProduct());
 }
コード例 #7
0
 /**
  * Get used product attributes
  *
  * @return array
  */
 protected function getUsedAttributes()
 {
     return $this->configurableType->getUsedProductAttributes($this->locator->getProduct());
 }
コード例 #8
0
ファイル: Config.php プロジェクト: Atlis/docker-magento2
 /**
  * Get list of used attributes
  *
  * @return array
  */
 public function getSelectedAttributes()
 {
     return $this->getProduct()->getTypeId() == Configurable::TYPE_CODE ? array_filter($this->_configurableType->getUsedProductAttributes($this->getProduct())) : array();
 }