Skip to content

Commit 42bef9e

Browse files
author
Serhiy Shkolyarenko
committed
MAGETWO-32010: Catalog product model and tables cleaning
generalized fixes for category, product and customer.
1 parent 08a8121 commit 42bef9e

File tree

6 files changed

+20
-173
lines changed

6 files changed

+20
-173
lines changed

app/code/Magento/Catalog/Model/Resource/Category.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -962,20 +962,4 @@ public function countVisible()
962962
$select->from($this->getEntityTable(), 'COUNT(*)')->where('parent_id != ?', 0);
963963
return (int)$adapter->fetchOne($select);
964964
}
965-
966-
/**
967-
* Return attribute row to prepare where statement
968-
*
969-
* @param \Magento\Framework\Object $entity
970-
* @param \Magento\Framework\Object $object
971-
* @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute
972-
* @return array
973-
*/
974-
protected function getAttributeRow($entity, $object, $attribute)
975-
{
976-
return [
977-
'attribute_id' => $attribute->getId(),
978-
$entity->getEntityIdField() => $object->getData($entity->getEntityIdField()),
979-
];
980-
}
981965
}

app/code/Magento/Catalog/Model/Resource/Product.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -630,59 +630,4 @@ public function validate($object)
630630
return parent::validate($object);
631631
}
632632

633-
/**
634-
* Overridden to get rid of entity_type_id check
635-
*
636-
* @param AbstractAttribute $attribute
637-
* @param \Magento\Framework\Object $object
638-
* @return bool
639-
* @throws \Magento\Eav\Exception
640-
*/
641-
public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
642-
{
643-
$adapter = $this->_getReadAdapter();
644-
$select = $adapter->select();
645-
if ($attribute->getBackend()->getType() === 'static') {
646-
$value = $object->getData($attribute->getAttributeCode());
647-
$bind = ['attribute_code' => trim($value)];
648-
649-
$select->from(
650-
$this->getEntityTable(),
651-
$this->getEntityIdField()
652-
)->where(
653-
$attribute->getAttributeCode() . ' = :attribute_code'
654-
);
655-
} else {
656-
$value = $object->getData($attribute->getAttributeCode());
657-
if ($attribute->getBackend()->getType() == 'datetime') {
658-
$date = new \Magento\Framework\Stdlib\DateTime\Date(
659-
$value,
660-
\Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT
661-
);
662-
$value = $date->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
663-
}
664-
$bind = [
665-
'attribute_id' => $attribute->getId(),
666-
'value' => trim($value),
667-
];
668-
$select->from(
669-
$attribute->getBackend()->getTable(),
670-
$attribute->getBackend()->getEntityIdField()
671-
)->where(
672-
'attribute_id = :attribute_id'
673-
)->where(
674-
'value = :value'
675-
);
676-
}
677-
$data = $adapter->fetchCol($select, $bind);
678-
679-
if ($object->getId()) {
680-
if (isset($data[0])) {
681-
return $data[0] == $object->getId();
682-
}
683-
return true;
684-
}
685-
686-
return !count($data);
687-
}
688633
}

app/code/Magento/Customer/Model/Resource/AbstractResource.php

Lines changed: 0 additions & 91 deletions
This file was deleted.

app/code/Magento/Customer/Model/Resource/Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use Magento\Framework\Exception\InputException;
1010

11-
class Address extends \Magento\Customer\Model\Resource\AbstractResource
11+
class Address extends \Magento\Eav\Model\Entity\AbstractEntity
1212
{
1313
/**
1414
* @var \Magento\Core\Model\Validator\Factory

app/code/Magento/Customer/Model/Resource/Customer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Customer entity resource model
1111
*/
12-
class Customer extends \Magento\Customer\Model\Resource\AbstractResource
12+
class Customer extends \Magento\Eav\Model\Entity\AbstractEntity
1313
{
1414
/**
1515
* @var \Magento\Core\Model\Validator\Factory

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -930,13 +930,11 @@ public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
930930
$select = $adapter->select();
931931
if ($attribute->getBackend()->getType() === 'static') {
932932
$value = $object->getData($attribute->getAttributeCode());
933-
$bind = ['entity_type_id' => $this->getTypeId(), 'attribute_code' => trim($value)];
933+
$bind = ['attribute_code' => trim($value)];
934934

935935
$select->from(
936936
$this->getEntityTable(),
937937
$this->getEntityIdField()
938-
)->where(
939-
'entity_type_id = :entity_type_id'
940938
)->where(
941939
$attribute->getAttributeCode() . ' = :attribute_code'
942940
);
@@ -947,21 +945,24 @@ public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
947945
$value = $date->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
948946
}
949947
$bind = [
950-
'entity_type_id' => $this->getTypeId(),
951948
'attribute_id' => $attribute->getId(),
952949
'value' => trim($value),
953950
];
954951
$select->from(
955952
$attribute->getBackend()->getTable(),
956953
$attribute->getBackend()->getEntityIdField()
957-
)->where(
958-
'entity_type_id = :entity_type_id'
959954
)->where(
960955
'attribute_id = :attribute_id'
961956
)->where(
962957
'value = :value'
963958
);
964959
}
960+
961+
if (!$this->getEntityTable()) {
962+
$bind['entity_type_id'] = $this->getTypeId();
963+
$select->where('entity_type_id = :entity_type_id');
964+
}
965+
965966
$data = $adapter->fetchCol($select, $bind);
966967

967968
if ($object->getId()) {
@@ -1517,12 +1518,15 @@ protected function _saveAttribute($object, $attribute, $value)
15171518
$entityIdField = $attribute->getBackend()->getEntityIdField();
15181519

15191520
$data = [
1520-
'entity_type_id' => $object->getEntityTypeId(),
15211521
$entityIdField => $object->getId(),
15221522
'attribute_id' => $attribute->getId(),
15231523
'value' => $this->_prepareValueForSave($value, $attribute),
15241524
];
15251525

1526+
if (!$this->getEntityTable()) {
1527+
$data['entity_type_id'] = $object->getEntityTypeId();
1528+
}
1529+
15261530
$this->_attributeValuesToSave[$table][] = $data;
15271531

15281532
return $this;
@@ -1663,11 +1667,16 @@ public function saveAttribute(\Magento\Framework\Object $object, $attributeCode)
16631667
*/
16641668
protected function getAttributeRow($entity, $object, $attribute)
16651669
{
1666-
return [
1667-
'entity_type_id' => $entity->getTypeId(),
1670+
$data = [
16681671
'attribute_id' => $attribute->getId(),
16691672
$entity->getEntityIdField() => $object->getData($entity->getEntityIdField()),
16701673
];
1674+
1675+
if (!$this->getEntityTable()) {
1676+
$data['entity_type_id'] = $entity->getTypeId();
1677+
}
1678+
1679+
return $data;
16711680
}
16721681

16731682
/**

0 commit comments

Comments
 (0)