Skip to content

Commit

Permalink
Merge pull request #1665 from magento-engcom/2.1-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - 2.1-develop
 - MAGETWO-83284: Add validation for number of street lines [Backport 2.1] #12022
 - MAGETWO-83205: Check attribute unique between same fields in magento commerce [backport 2.1] #11621
  • Loading branch information
ishakhsuvarov authored Nov 6, 2017
2 parents 9d75bca + 77a6e29 commit 8ffe3cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/code/Magento/Customer/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
<field id="street_lines" translate="label comment" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
<label>Number of Lines in a Street Address</label>
<backend_model>Magento\Customer\Model\Config\Backend\Address\Street</backend_model>
<comment>Leave empty for default (2). Valid range: 1-4</comment>
<comment>Valid range: 1-4</comment>
<validate>required-entry validate-digits validate-digits-range digits-range-1-4</validate>
</field>
<field id="prefix_show" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Show Prefix</label>
Expand Down
20 changes: 13 additions & 7 deletions app/code/Magento/Eav/Model/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,28 +928,33 @@ public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
{
$connection = $this->getConnection();
$select = $connection->select();
if ($attribute->getBackend()->getType() === 'static') {

$entityIdField = $this->getEntityIdField();
$attributeBackend = $attribute->getBackend();
if ($attributeBackend->getType() === 'static') {
$value = $object->getData($attribute->getAttributeCode());
$bind = ['value' => trim($value)];

$select->from(
$this->getEntityTable(),
$this->getEntityIdField()
$entityIdField
)->where(
$attribute->getAttributeCode() . ' = :value'
);
} else {
$value = $object->getData($attribute->getAttributeCode());
if ($attribute->getBackend()->getType() == 'datetime') {
if ($attributeBackend->getType() == 'datetime') {
$value = (new \DateTime($value))->format('Y-m-d H:i:s');
}
$bind = [
'attribute_id' => $attribute->getId(),
'value' => trim($value),
];

$entityIdField = $object->getResource()->getLinkField();
$select->from(
$attribute->getBackend()->getTable(),
$object->getResource()->getLinkField()
$attributeBackend->getTable(),
$entityIdField
)->where(
'attribute_id = :attribute_id'
)->where(
Expand All @@ -964,9 +969,10 @@ public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)

$data = $connection->fetchCol($select, $bind);

if ($object->getId()) {
$objectId = $object->getData($entityIdField);
if ($objectId) {
if (isset($data[0])) {
return $data[0] == $object->getId();
return $data[0] == $objectId;
}
return true;
}
Expand Down

0 comments on commit 8ffe3cc

Please sign in to comment.