/** * Involve new customer to system * * @return $this */ protected function _involveNewCustomer() { $customer = $this->_quote->getCustomer(); $confirmationStatus = $this->_accountManagement->getConfirmationStatus($customer->getId()); if ($confirmationStatus === AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED) { $this->_messageManager->addSuccess(__('Thank you for registering with Main Website Store.')); } else { $this->getCustomerSession()->regenerateId(); $this->getCustomerSession()->loginById($customer->getId()); } return $this; }
/** * Involve new customer to system * * @return $this */ protected function _involveNewCustomer() { $customer = $this->_quote->getCustomer(); $confirmationStatus = $this->_accountManagement->getConfirmationStatus($customer->getId()); if ($confirmationStatus === AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED) { $url = $this->_customerUrl->getEmailConfirmationUrl($customer->getEmail()); $this->_messageManager->addSuccess(__('Account confirmation is required. Please check your email for confirmation link. To resend confirmation email please <a href="%1">click here</a>.', $url)); } else { $this->getCustomerSession()->regenerateId(); $this->getCustomerSession()->loginById($customer->getId()); } return $this; }
/** * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function testSetCustomerAddressData() { $customerId = 1; $addressMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false, true, true, ['getId']); $addressMock->expects($this->any())->method('getId')->will($this->returnValue(null)); $addresses = [$addressMock]; $customerMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false); $customerResultMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false); $this->customerRepositoryMock->expects($this->once())->method('getById')->will($this->returnValue($customerMock)); $customerMock->expects($this->once())->method('getAddresses')->will($this->returnValue($addresses)); $result = $this->quote->setCustomerAddressData([$addressMock]); $this->assertInstanceOf('Magento\\Quote\\Model\\Quote', $result); $this->assertEquals($customerResultMock, $this->quote->getCustomer()); }
/** * Populate customer model * * @param Quote $quote * @return void */ public function populateCustomerInfo(QuoteEntity $quote) { $customer = $quote->getCustomer(); if (!$customer->getId()) { $customer = $this->accountManagement->createAccountWithPasswordHash($customer, $quote->getPasswordHash()); $quote->setCustomer($customer); } else { $this->customerRepository->save($customer); } if (!$quote->getBillingAddress()->getId() && $customer->getDefaultBilling()) { $quote->getBillingAddress()->importCustomerAddressData($this->customerAddressRepository->getById($customer->getDefaultBilling())); $quote->getBillingAddress()->setCustomerAddressId($customer->getDefaultBilling()); } if (!$quote->getShippingAddress()->getSameAsBilling() && !$quote->getBillingAddress()->getId() && $customer->getDefaultShipping()) { $quote->getShippingAddress()->importCustomerAddressData($this->customerAddressRepository->getById($customer->getDefaultShipping())); $quote->getShippingAddress()->setCustomerAddressId($customer->getDefaultShipping()); } }
/** * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function testSetCustomerAddressData() { $customerId = 1; $addressMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false, true, true, ['getId']); $addressMock->expects($this->any())->method('getId')->will($this->returnValue(null)); $addresses = [$addressMock]; $customerMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false); $customerResultMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false); $requestMock = $this->getMock('\\Magento\\Framework\\DataObject'); $this->extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->will($this->returnValue(['customer_id' => $customerId])); $this->customerRepositoryMock->expects($this->any())->method('getById')->will($this->returnValue($customerMock)); $this->customerDataFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerMock)); $this->customerRepositoryMock->expects($this->once())->method('save')->will($this->returnValue($customerMock)); $customerMock->expects($this->any())->method('getAddresses')->will($this->returnValue($addresses)); $this->objectFactoryMock->expects($this->once())->method('create')->with($this->equalTo(['customer_id' => $customerId]))->will($this->returnValue($requestMock)); $result = $this->quote->setCustomerAddressData([$addressMock]); $this->assertInstanceOf('Magento\\Quote\\Model\\Quote', $result); $this->assertEquals($customerResultMock, $this->quote->getCustomer()); }
private function configureTaxCalculation() { // this prevents customer session initialization (which affects cookies) // see Mage_Tax_Model_Calculation::getCustomer() $this->calculation->setCustomer($this->quote->getCustomer()); }
/** * @param Quote|\Magento\Quote\Api\Data\CartInterface $quote * * @return bool */ protected function _isAvailableRatePay($quote) { $dob = $quote->getCustomer()->getDob(); $minAge = (int) $this->getConfigData('min_age'); if ($minAge <= 0) { $this->_logger->debug(__METHOD__ . ':warning min-age not set for ratepay'); return false; } //we only need to check the dob if it's set. Else we ask for dob on payment selection page. if ($dob) { $dobObject = new \DateTime($dob); $currentYear = date('Y'); $currentMonth = date('m'); $currentDay = date('d'); $ageCheckDate = $currentYear - $minAge . '-' . $currentMonth . '-' . $currentDay; $ageCheckObject = new \DateTime($ageCheckDate); if ($ageCheckObject < $dobObject) { return false; } } if ($quote->hasVirtualItems()) { return false; } if ($this->getConfigData('billing_shipping_address_identical') && !$this->compareAddresses($quote)) { return false; } $currencies = explode(',', $this->getConfigData('currency')); if (!in_array($quote->getQuoteCurrencyCode(), $currencies)) { return false; } if (strlen($this->getConfigData('shippingcountry'))) { $countries = explode(',', $this->getConfigData('shippingcountry')); if (!in_array($quote->getShippingAddress()->getCountry(), $countries)) { return false; } } if (strlen($this->getConfigData('max_basket_size'))) { if ($quote->getItemsQty() > $this->getConfigData('max_basket_size')) { return false; } } if (strlen($this->getConfigData('min_basket_size'))) { if ($quote->getItemsQty() < $this->getConfigData('min_basket_size')) { return false; } } return parent::isAvailable($quote); }