/**
  * test _beforeSaveMethod via save() with failed validation
  *
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage We can't save the address:
  */
 public function testSaveValidationFailed()
 {
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->addressMock)->willReturn(true);
     $this->addressMock->expects($this->any())->method('hasDataChanges')->will($this->returnValue(true));
     $this->validatorMock->expects($this->once())->method('validate')->with($this->equalTo($this->addressMock))->will($this->returnValue(['warning message']));
     $this->addressResource->save($this->addressMock);
 }
 /**
  * Run test validate
  *
  * @param $addressData
  * @param $email
  * @param $addressType
  * @param $expectedWarnings
  * @dataProvider providerAddressData
  */
 public function testValidate($addressData, $email, $addressType, $expectedWarnings)
 {
     $this->addressMock->expects($this->any())->method('hasData')->will($this->returnValueMap($addressData));
     $this->addressMock->expects($this->once())->method('getEmail')->will($this->returnValue($email));
     $this->addressMock->expects($this->once())->method('getAddressType')->will($this->returnValue($addressType));
     $actualWarnings = $this->validator->validate($this->addressMock);
     $this->assertEquals($expectedWarnings, $actualWarnings);
 }
 public function testGetName()
 {
     $this->address->setData('suffix', 'suffix');
     $this->address->setData('prefix', 'prefix');
     $this->address->setData('firstname', 'firstname');
     $this->address->setData('middlename', 'middlename');
     $this->address->setData('lastname', 'lastname');
     $this->assertEquals('prefix firstname middlename lastname suffix', $this->address->getName());
 }
 /**
  * Format address in a specific way
  *
  * @param Address $address
  * @param string $type
  * @return string|null
  */
 public function format(Address $address, $type)
 {
     $formatType = $this->addressConfig->getFormatByCode($type);
     if (!$formatType || !$formatType->getRenderer()) {
         return null;
     }
     $this->eventManager->dispatch('customer_address_format', ['type' => $formatType, 'address' => $address]);
     return $formatType->getRenderer()->renderArray($address->getData());
 }
 /**
  * test _beforeSaveMethod via save()
  */
 public function testSave()
 {
     $this->validatorMock->expects($this->once())->method('validate')->with($this->equalTo($this->addressMock))->will($this->returnValue([]));
     $this->addressMock->expects($this->once())->method('hasDataChanges')->will($this->returnValue(true));
     $this->addressMock->expects($this->exactly(2))->method('getOrderId')->will($this->returnValue(2));
     $this->gridPoolMock->expects($this->once())->method('refreshByOrderId')->with($this->equalTo(2))->will($this->returnSelf());
     $this->addressResource->save($this->addressMock);
     $this->assertTrue(true);
 }
 /**
  * Test process method with shipping_address
  */
 public function testProcessShippingAddress()
 {
     $this->orderMock->expects($this->exactly(2))->method('getAddresses')->willReturn([$this->addressMock]);
     $this->addressMock->expects($this->once())->method('save')->will($this->returnSelf());
     $this->orderMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue(null));
     $this->orderMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($this->addressMock));
     $this->addressMock->expects($this->exactly(2))->method('getId')->will($this->returnValue(2));
     $this->orderMock->expects($this->once())->method('setShippingAddressId')->will($this->returnSelf());
     $this->attributeMock->expects($this->once())->method('saveAttribute')->with($this->orderMock, ['shipping_address_id'])->will($this->returnSelf());
     $this->assertEquals($this->address, $this->address->process($this->orderMock));
 }
Exemple #7
0
 /**
  *
  * @param \Magento\Sales\Model\Order\Address $address
  * @return array
  */
 public function validate(Address $address)
 {
     $warnings = [];
     foreach ($this->required as $code => $label) {
         if (!$address->hasData($code)) {
             $warnings[] = sprintf('%s is a required field', $label);
         }
     }
     if (!filter_var($address->getEmail(), FILTER_VALIDATE_EMAIL)) {
         $warnings[] = 'Email has a wrong format';
     }
     if (!filter_var(in_array($address->getAddressType(), [Address::TYPE_BILLING, Address::TYPE_SHIPPING]))) {
         $warnings[] = 'Address type doesn\'t match required options';
     }
     return $warnings;
 }
 /**
  * Validate address attribute for customer creation
  *
  * @return bool|array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * @param Address $address
  */
 public function validateForCustomer(Address $address)
 {
     if ($address->getShouldIgnoreValidation()) {
         return true;
     }
     $errors = [];
     if ($this->isEmpty($address->getFirstname())) {
         $errors[] = __('Please enter the first name.');
     }
     if ($this->isEmpty($address->getLastname())) {
         $errors[] = __('Please enter the last name.');
     }
     if ($this->isEmpty($address->getStreetLine(1))) {
         $errors[] = __('Please enter the street.');
     }
     if ($this->isEmpty($address->getCity())) {
         $errors[] = __('Please enter the city.');
     }
     if ($this->isEmpty($address->getTelephone())) {
         $errors[] = __('Please enter the phone number.');
     }
     $countryId = $address->getCountryId();
     if ($this->isZipRequired($countryId) && $this->isEmpty($address->getPostcode())) {
         $errors[] = __('Please enter the zip/postal code.');
     }
     if ($this->isEmpty($countryId)) {
         $errors[] = __('Please enter the country.');
     }
     if ($this->isStateRequired($countryId) && $this->isEmpty($address->getRegionId())) {
         $errors[] = __('Please enter the state/province.');
     }
     return empty($errors) ? true : $errors;
 }
Exemple #9
0
 /**
  * @magentoDataFixture Magento/Sales/_files/order.php
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_address.php
  */
 public function testSave()
 {
     /** @var \Magento\Sales\Model\Order $order */
     $order = Bootstrap::getObjectManager()->create('Magento\\Sales\\Model\\Order');
     /** @var \Magento\Customer\Service\V1\CustomerAddressServiceInterface $customerAddressService */
     $customerAddressService = Bootstrap::getObjectManager()->get('Magento\\Customer\\Service\\V1\\CustomerAddressServiceInterface');
     $order->loadByIncrementId('100000001');
     $this->_model->setOrder($order);
     $this->_model->setData($customerAddressService->getAddress(1)->__toArray());
     $this->_model->setEmail('*****@*****.**');
     $this->_model->setAddressType('billing');
     $this->_model->setRegionId(1);
     $this->_model->save();
     $this->assertEquals($order->getId(), $this->_model->getParentId());
 }
Exemple #10
0
 /**
  * @param \Magento\Sales\Model\Order\Address $address
  * @return $this
  */
 public function addAddress(\Magento\Sales\Model\Order\Address $address)
 {
     $address->setOrder($this)->setParentId($this->getId());
     if (!$address->getId()) {
         $this->setAddresses(array_merge($this->getAddresses(), [$address]));
         $this->setDataChanges(true);
     }
     return $this;
 }
Exemple #11
0
 /**
  * @param \Magento\Sales\Model\Order\Address $address
  * @return $this
  */
 public function addAddress(\Magento\Sales\Model\Order\Address $address)
 {
     $address->setOrder($this)->setParentId($this->getId());
     if (!$address->getId()) {
         $this->getAddressesCollection()->addItem($address);
         $this->setDataChanges(true);
     }
     return $this;
 }
Exemple #12
0
/**
 * 2016-04-04
 * @param AA|CA|QA|OA $a
 * @return Customer|Quote|Order|null
 */
function df_address_owner($a)
{
    return $a instanceof CA ? $a->getCustomer() : ($a instanceof QA ? $a->getQuote() : ($a instanceof OA ? $a->getOrder() : null));
}
Exemple #13
0
 /**
  * Convert order address to quote address
  *
  * @param   \Magento\Sales\Model\Order\Address $address
  * @return  \Magento\Sales\Model\Quote\Address
  */
 public function addressToQuoteAddress(\Magento\Sales\Model\Order\Address $address)
 {
     $quoteAddress = $this->_quoteAddressFactory->create()->setStoreId($address->getStoreId())->setAddressType($address->getAddressType())->setCustomerId($address->getCustomerId())->setCustomerAddressId($address->getCustomerAddressId());
     $this->_objectCopyService->copyFieldsetToTarget('sales_convert_order_address', 'to_quote_address', $address, $quoteAddress);
     return $quoteAddress;
 }
Exemple #14
0
 /**
  * Set recipient details into request
  * @param \Magento\Shipping\Model\Shipment\Request $request
  * @param \Magento\Sales\Model\Order\Address $address
  * @return void
  */
 protected function setRecipientDetails(Request $request, Address $address)
 {
     $request->setRecipientContactPersonName(trim($address->getFirstname() . ' ' . $address->getLastname()));
     $request->setRecipientContactPersonFirstName($address->getFirstname());
     $request->setRecipientContactPersonLastName($address->getLastname());
     $request->setRecipientContactCompanyName($address->getCompany());
     $request->setRecipientContactPhoneNumber($address->getTelephone());
     $request->setRecipientEmail($address->getEmail());
     $request->setRecipientAddressStreet(trim($address->getStreetLine(1) . ' ' . $address->getStreetLine(2)));
     $request->setRecipientAddressStreet1($address->getStreetLine(1));
     $request->setRecipientAddressStreet2($address->getStreetLine(2));
     $request->setRecipientAddressCity($address->getCity());
     $request->setRecipientAddressStateOrProvinceCode($address->getRegionCode() ?: $address->getRegion());
     $request->setRecipientAddressRegionCode($address->getRegionCode());
     $request->setRecipientAddressPostalCode($address->getPostcode());
     $request->setRecipientAddressCountryCode($address->getCountryId());
 }
 /**
  * @magentoDataFixture Magento/Sales/_files/order.php
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_address.php
  */
 public function testSave()
 {
     /** @var \Magento\Sales\Model\Order $order */
     $order = Bootstrap::getObjectManager()->create('Magento\\Sales\\Model\\Order');
     $order->loadByIncrementId('100000001');
     $this->_model->setOrder($order);
     $this->_model->setEmail('*****@*****.**');
     $this->_model->setPostcode('12345');
     $this->_model->setLastname('LastName');
     $this->_model->setStreet('Street');
     $this->_model->setCity('City');
     $this->_model->setTelephone('123-45-67');
     $this->_model->setCountryId(1);
     $this->_model->setFirstname('FirstName');
     $this->_model->setAddressType('billing');
     $this->_model->setRegionId(1);
     $this->_model->save();
     $this->assertEquals($order->getId(), $this->_model->getParentId());
 }
Exemple #16
0
 /**
  * Import address data from order address
  *
  * @param   \Magento\Sales\Model\Order\Address $address
  * @return $this
  * @deprecated Use \Magento\Sales\Model\Quote\Address::importCustomerAddressData() instead
  */
 public function importOrderAddress(\Magento\Sales\Model\Order\Address $address)
 {
     $this->setAddressType($address->getAddressType())->setCustomerId($address->getCustomerId())->setCustomerAddressId($address->getCustomerAddressId())->setEmail($address->getEmail());
     $this->_objectCopyService->copyFieldsetToTarget('sales_convert_order_address', 'to_quote_address', $address, $this);
     return $this;
 }
Exemple #17
0
 /**
  * Get link to edit order address page
  *
  * @param \Magento\Sales\Model\Order\Address $address
  * @param string $label
  * @return string
  */
 public function getAddressEditLink($address, $label = '')
 {
     if ($this->_authorization->isAllowed('Magento_Sales::actions_edit')) {
         if (empty($label)) {
             $label = __('Edit');
         }
         $url = $this->getUrl('sales/order/address', array('address_id' => $address->getId()));
         return '<a href="' . $url . '">' . $label . '</a>';
     }
     return '';
 }