Exemplo n.º 1
0
 /**
  * Save Custom labels for Attribute name
  *
  * @param \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute $attribute
  * @return $this
  */
 public function saveLabel($attribute)
 {
     $adapter = $this->_getWriteAdapter();
     $select = $adapter->select()->from($this->_labelTable, 'value_id')->where('product_super_attribute_id = :product_super_attribute_id')->where('store_id = :store_id');
     $bind = ['product_super_attribute_id' => (int) $attribute->getId(), 'store_id' => (int) $attribute->getStoreId()];
     $valueId = $adapter->fetchOne($select, $bind);
     if ($valueId) {
         $adapter->update($this->_labelTable, ['use_default' => (int) $attribute->getUseDefault(), 'value' => $attribute->getLabel()], $adapter->quoteInto('value_id = ?', (int) $valueId));
     } else {
         $adapter->insert($this->_labelTable, ['product_super_attribute_id' => (int) $attribute->getId(), 'store_id' => (int) $attribute->getStoreId(), 'use_default' => (int) $attribute->getUseDefault(), 'value' => $attribute->getLabel()]);
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Save Custom labels for Attribute name
  *
  * @param \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute $attribute
  * @return $this
  */
 public function saveLabel($attribute)
 {
     $connection = $this->getConnection();
     $select = $connection->select()->from($this->_labelTable, 'value_id')->where('product_super_attribute_id = :product_super_attribute_id')->where('store_id = :store_id');
     $bind = ['product_super_attribute_id' => (int) $attribute->getId(), 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID];
     $valueId = $connection->fetchOne($select, $bind);
     if ($valueId) {
         $storeId = (int) $attribute->getStoreId() ?: $this->_storeManager->getStore()->getId();
     } else {
         // if attribute label not exists, always store on default store (0)
         $storeId = Store::DEFAULT_STORE_ID;
     }
     $connection->insertOnDuplicate($this->_labelTable, ['product_super_attribute_id' => (int) $attribute->getId(), 'use_default' => (int) $attribute->getUseDefault(), 'store_id' => $storeId, 'value' => $attribute->getLabel()], ['value', 'use_default']);
     return $this;
 }