Example #1
0
 /**
  * Resolve customers data based on ids quote table.
  *
  * @return void
  */
 public function resolveCustomerNames()
 {
     $select = $this->customerResource->getReadConnection()->select();
     $customerName = $select->getAdapter()->getConcatSql(['firstname', 'lastname'], ' ');
     $select->from(['customer' => $this->customerResource->getTable('customer_entity')], ['email'])->columns(['customer_name' => $customerName])->where('customer.entity_id IN (?)', array_column($this->getData(), 'customer_id'));
     $customersData = $select->getAdapter()->fetchAll($select);
     foreach ($this->getItems() as $item) {
         $item->setData(array_merge($item->getData(), current($customersData)));
         next($customersData);
     }
 }
Example #2
0
 /**
  * Test _saveCustomerDefaults
  *
  * @magentoDataFixture Magento/Customer/_files/import_export/customer_with_addresses.php
  */
 public function testSaveCustomerDefaults()
 {
     /** @var $objectManager \Magento\TestFramework\ObjectManager */
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     // get not default address
     $customers = $objectManager->get('Magento\\Framework\\Registry')->registry($this->_fixtureKey);
     /** @var $notDefaultAddress \Magento\Customer\Model\Address */
     $notDefaultAddress = null;
     /** @var $addressCustomer \Magento\Customer\Model\Customer */
     $addressCustomer = null;
     /** @var $customer \Magento\Customer\Model\Customer */
     foreach ($customers as $customer) {
         /** @var $address \Magento\Customer\Model\Address */
         foreach ($customer->getAddressesCollection() as $address) {
             if (!$customer->getDefaultBillingAddress() && !$customer->getDefaultShippingAddress()) {
                 $notDefaultAddress = $address;
                 $addressCustomer = $customer;
                 break;
             }
             if ($notDefaultAddress) {
                 break;
             }
         }
     }
     $this->assertNotNull($notDefaultAddress, 'Not default address must exists.');
     $this->assertNotNull($addressCustomer, 'Not default address customer must exists.');
     $addressId = $notDefaultAddress->getId();
     $customerId = $addressCustomer->getId();
     // set customer defaults
     $defaults = [$this->customerResource->getTable('customer_entity') => [$customerId => ['default_billing' => $addressId, 'default_shipping' => $addressId]]];
     // invoke _saveCustomerDefaults
     $saveDefaults = new \ReflectionMethod($this->_testClassName, '_saveCustomerDefaults');
     $saveDefaults->setAccessible(true);
     $saveDefaults->invoke($this->_entityAdapter, $defaults);
     // check DB
     /** @var $testCustomer \Magento\Customer\Model\Customer */
     $testCustomer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Customer');
     $testCustomer->load($customerId);
     $this->assertEquals($customerId, $testCustomer->getId(), 'Customer must exists.');
     $this->assertNotNull($testCustomer->getDefaultBillingAddress(), 'Default billing address must exists.');
     $this->assertNotNull($testCustomer->getDefaultShippingAddress(), 'Default shipping address must exists.');
     $this->assertEquals($addressId, $testCustomer->getDefaultBillingAddress()->getId(), 'Incorrect default billing address.');
     $this->assertEquals($addressId, $testCustomer->getDefaultShippingAddress()->getId(), 'Incorrect default shipping address.');
 }