Example #1
0
 /**
  * Update attribute value for specific store
  *
  * @param \Magento\Catalog\Model\AbstractModel $object
  * @param object $attribute
  * @param mixed $value
  * @param int $storeId
  * @return $this
  */
 protected function _updateAttributeForStore($object, $attribute, $value, $storeId)
 {
     $adapter = $this->_getWriteAdapter();
     $table = $attribute->getBackend()->getTable();
     $entityIdField = $attribute->getBackend()->getEntityIdField();
     $select = $adapter->select()->from($table, 'value_id')->where('entity_type_id = :entity_type_id')->where("{$entityIdField} = :entity_field_id")->where('store_id = :store_id')->where('attribute_id = :attribute_id');
     $bind = array('entity_type_id' => $object->getEntityTypeId(), 'entity_field_id' => $object->getId(), 'store_id' => $storeId, 'attribute_id' => $attribute->getId());
     $valueId = $adapter->fetchOne($select, $bind);
     /**
      * When value for store exist
      */
     if ($valueId) {
         $bind = array('value' => $this->_prepareValueForSave($value, $attribute));
         $where = array('value_id = ?' => (int) $valueId);
         $adapter->update($table, $bind, $where);
     } else {
         $bind = array($entityIdField => (int) $object->getId(), 'entity_type_id' => (int) $object->getEntityTypeId(), 'attribute_id' => (int) $attribute->getId(), 'value' => $this->_prepareValueForSave($value, $attribute), 'store_id' => (int) $storeId);
         $adapter->insert($table, $bind);
     }
     return $this;
 }