示例#1
0
 /**
  * @param string $entityType
  * @param string $value
  * @param AbstractAttribute $attribute
  * @return string
  * @throws \Exception
  */
 protected function prepareValue($entityType, $value, AbstractAttribute $attribute)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $type = $attribute->getBackendType();
     if (($type == 'int' || $type == 'decimal' || $type == 'datetime') && $value === '') {
         $value = null;
     } elseif ($type == 'decimal') {
         $value = $this->localeFormat->getNumber($value);
     }
     $describe = $metadata->getEntityConnection()->describeTable($attribute->getBackendTable());
     return $metadata->getEntityConnection()->prepareColumnValue($describe['value'], $value);
 }
示例#2
0
 /**
  * Prepare value for save
  *
  * @param mixed $value
  * @param AbstractAttribute $attribute
  * @return mixed
  */
 protected function _prepareValueForSave($value, AbstractAttribute $attribute)
 {
     $type = $attribute->getBackendType();
     if (($type == 'int' || $type == 'decimal' || $type == 'datetime') && $value === '') {
         $value = null;
     } elseif ($type == 'decimal') {
         $value = $this->_localeFormat->getNumber($value);
     }
     $backendTable = $attribute->getBackendTable();
     if (!isset(self::$_attributeBackendTables[$backendTable])) {
         self::$_attributeBackendTables[$backendTable] = $this->_getReadAdapter()->describeTable($backendTable);
     }
     $describe = self::$_attributeBackendTables[$backendTable];
     return $this->_getReadAdapter()->prepareColumnValue($describe['value'], $value);
 }
示例#3
0
 /**
  * Load options for attribute
  *
  * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $superAttribute
  * @param int $productId
  * @return array
  */
 public function getAttributeOptions($superAttribute, $productId)
 {
     $scope = $this->getScopeResolver()->getScope();
     $select = $this->getConnection()->select()->from(['super_attribute' => $this->getTable('catalog_product_super_attribute')], ['sku' => 'entity.sku', 'product_id' => 'product_entity.entity_id', 'attribute_code' => 'attribute.attribute_code', 'value_index' => 'entity_value.value', 'option_title' => $this->getConnection()->getIfNullSql('option_value.value', 'default_option_value.value'), 'default_title' => 'default_option_value.value'])->joinInner(['product_entity' => $this->getTable('catalog_product_entity')], "product_entity.{$this->getProductEntityLinkField()} = super_attribute.product_id", [])->joinInner(['product_link' => $this->getTable('catalog_product_super_link')], 'product_link.parent_id = super_attribute.product_id', [])->joinInner(['attribute' => $this->getTable('eav_attribute')], 'attribute.attribute_id = super_attribute.attribute_id', [])->joinInner(['entity' => $this->getTable('catalog_product_entity')], 'entity.entity_id = product_link.product_id', [])->joinInner(['entity_value' => $superAttribute->getBackendTable()], implode(' AND ', ['entity_value.attribute_id = super_attribute.attribute_id', 'entity_value.store_id = 0', "entity_value.{$this->getProductEntityLinkField()} = " . "entity.{$this->getProductEntityLinkField()}"]), [])->joinLeft(['option_value' => $this->getTable('eav_attribute_option_value')], implode(' AND ', ['option_value.option_id = entity_value.value', 'option_value.store_id = ' . $scope->getId()]), [])->joinLeft(['default_option_value' => $this->getTable('eav_attribute_option_value')], implode(' AND ', ['default_option_value.option_id = entity_value.value', 'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID]), [])->where('super_attribute.product_id = ?', $productId)->where('attribute.attribute_id = ?', $superAttribute->getAttributeId());
     return $this->getConnection()->fetchAll($select);
 }