Skip to content

Commit 074f66f

Browse files
author
nsyvokonenko
committed
MAGETWO-37611: Refactor direct calls to attribute tables
1 parent 8fa7f8d commit 074f66f

File tree

2 files changed

+31
-40
lines changed

2 files changed

+31
-40
lines changed

app/code/Magento/Reports/Model/Resource/Quote/Collection.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@ public function prepareForAbandonedReport($storeIds, $filter = null)
6868
return $this;
6969
}
7070

71+
/**
72+
* Add customer data
73+
*
74+
* @param array|null $filter
75+
* @return $this
76+
*/
77+
public function addCustomerData($filter = null)
78+
{
79+
$customersSelect = $this->customerResource->getReadConnection()->select();
80+
$customersSelect->from(
81+
['customer' => $this->customerResource->getTable('customer_entity')],
82+
'entity_id'
83+
);
84+
if (isset($filter['customer_name'])) {
85+
$customerName = $customersSelect->getAdapter()
86+
->getConcatSql(['customer.firstname', 'customer.lastname'], ' ');
87+
$customersSelect->where(
88+
$customerName . ' LIKE ?', '%' . $filter['customer_name'] . '%'
89+
);
90+
}
91+
if (isset($filter['email'])) {
92+
$customersSelect->where('customer.email LIKE ?', '%' . $filter['email'] . '%');
93+
}
94+
$filteredCustomers = $this->customerResource->getReadConnection()->fetchCol($customersSelect);
95+
$this->getSelect()->where('main_table.customer_id IN (?)', $filteredCustomers);
96+
return $this;
97+
}
98+
7199
/**
72100
* Add subtotals
73101
*

app/code/Magento/Reports/Model/Resource/Review/Customer/Collection.php

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -78,50 +78,13 @@ protected function _joinCustomers()
7878
{
7979
/** @var $adapter \Magento\Framework\DB\Adapter\AdapterInterface */
8080
$adapter = $this->getConnection();
81-
/** @var $firstnameAttr \Magento\Eav\Model\Entity\Attribute */
82-
$firstnameAttr = $this->_customerResource->getAttribute('firstname');
83-
/** @var $lastnameAttr \Magento\Eav\Model\Entity\Attribute */
84-
$lastnameAttr = $this->_customerResource->getAttribute('lastname');
85-
86-
$firstnameCondition = ['table_customer_firstname.entity_id = detail.customer_id'];
87-
88-
if ($firstnameAttr->getBackend()->isStatic()) {
89-
$firstnameField = 'firstname';
90-
} else {
91-
$firstnameField = 'value';
92-
$firstnameCondition[] = $adapter->quoteInto(
93-
'table_customer_firstname.attribute_id = ?',
94-
(int)$firstnameAttr->getAttributeId()
95-
);
96-
}
97-
98-
$this->getSelect()->joinInner(
99-
['table_customer_firstname' => $firstnameAttr->getBackend()->getTable()],
100-
implode(' AND ', $firstnameCondition),
101-
[]
102-
);
103-
104-
$lastnameCondition = ['table_customer_lastname.entity_id = detail.customer_id'];
105-
if ($lastnameAttr->getBackend()->isStatic()) {
106-
$lastnameField = 'lastname';
107-
} else {
108-
$lastnameField = 'value';
109-
$lastnameCondition[] = $adapter->quoteInto(
110-
'table_customer_lastname.attribute_id = ?',
111-
(int)$lastnameAttr->getAttributeId()
112-
);
113-
}
114-
11581
//Prepare fullname field result
116-
$customerFullname = $adapter->getConcatSql(
117-
["table_customer_firstname.{$firstnameField}", "table_customer_lastname.{$lastnameField}"],
118-
' '
119-
);
82+
$customerFullname = $adapter->getConcatSql(['customer.firstname', 'customer.lastname'], ' ');
12083
$this->getSelect()->reset(
12184
\Zend_Db_Select::COLUMNS
12285
)->joinInner(
123-
['table_customer_lastname' => $lastnameAttr->getBackend()->getTable()],
124-
implode(' AND ', $lastnameCondition),
86+
['customer' => $adapter->getTableName('customer_entity')],
87+
'customer.entity_id = detail.customer_id',
12588
[]
12689
)->columns(
12790
[

0 commit comments

Comments
 (0)