From 9205f16e41d57174861beff6e5e1317ad59d088b Mon Sep 17 00:00:00 2001 From: Volodymyr Kholoshenko Date: Fri, 22 May 2015 13:14:17 +0300 Subject: [PATCH 1/2] MAGETWO-37836: Fatal error on Abandoned Carts report grid --- .../Model/Resource/Quote/Collection.php | 26 +++++++++++++++++++ .../Adminhtml/Shopcart/Abandoned/GridTest.php | 1 + 2 files changed, 27 insertions(+) diff --git a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php index fc5ed24362727..82b7c11ad5f58 100644 --- a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php @@ -166,4 +166,30 @@ protected function getCustomerNames($select) ); return $select; } + + /** + * Add customer data + * + * @param array|null $filter + * @return $this + */ + public function addCustomerData($filter = null) + { + $customersSelect = $this->customerResource->getReadConnection()->select(); + $customersSelect->from(['customer' => 'customer_entity'], 'entity_id'); + if (isset($filter['customer_name'])) { + $customersSelect = $this->getCustomerNames($customersSelect); + $customerName = $customersSelect->getAdapter()->getConcatSql(['cust_fname.value', 'cust_lname.value'], ' '); + $customersSelect->where( + $customerName . ' LIKE ?', + '%' . $filter['customer_name'] . '%' + ); + } + if (isset($filter['email'])) { + $customersSelect->where('customer.email LIKE ?', '%' . $filter['email'] . '%'); + } + $filteredCustomers = $this->customerResource->getReadConnection()->fetchCol($customersSelect); + $this->getSelect()->where('main_table.customer_id IN (?)', $filteredCustomers); + return $this; + } } diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php index c5e7f6fd6978c..b8805203654f5 100644 --- a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php +++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php @@ -26,6 +26,7 @@ public function testGridContent() $layout = Bootstrap::getObjectManager()->get('Magento\Framework\View\LayoutInterface'); /** @var Grid $grid */ $grid = $layout->createBlock('Magento\Reports\Block\Adminhtml\Shopcart\Abandoned\Grid'); + $grid->getRequest()->setParams(['filter' => base64_encode(urlencode('email=customer@example.com'))]); $result = $grid->getPreparedCollection(); $this->assertCount(1, $result->getItems()); From 8298ea8a308a381fbc88c0eadecf651bae106b42 Mon Sep 17 00:00:00 2001 From: Volodymyr Kholoshenko Date: Fri, 22 May 2015 15:33:31 +0300 Subject: [PATCH 2/2] MAGETWO-37836: Fatal error on Abandoned Carts report grid - fix usage of table customer_entity --- app/code/Magento/Reports/Model/Resource/Quote/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php index 82b7c11ad5f58..6054469f4afc3 100644 --- a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php @@ -176,7 +176,7 @@ protected function getCustomerNames($select) public function addCustomerData($filter = null) { $customersSelect = $this->customerResource->getReadConnection()->select(); - $customersSelect->from(['customer' => 'customer_entity'], 'entity_id'); + $customersSelect->from(['customer' => $this->getTable('customer_entity')], 'entity_id'); if (isset($filter['customer_name'])) { $customersSelect = $this->getCustomerNames($customersSelect); $customerName = $customersSelect->getAdapter()->getConcatSql(['cust_fname.value', 'cust_lname.value'], ' ');