• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Api\AddressRepositoryInterface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Magento\Customer\Api\AddressRepositoryInterface的典型用法代码示例。如果您正苦于以下问题:PHP AddressRepositoryInterface类的具体用法?PHP AddressRepositoryInterface怎么用?PHP AddressRepositoryInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了AddressRepositoryInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: save

 /**
  * @param CartInterface $quote
  * @param AddressInterface $address
  * @param bool $useForShipping
  * @return void
  * @throws NoSuchEntityException
  * @throws InputException
  */
 public function save(CartInterface $quote, AddressInterface $address, $useForShipping = false)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $this->addressValidator->validate($address);
     $customerAddressId = $address->getCustomerAddressId();
     $shippingAddress = null;
     $addressData = [];
     if ($useForShipping) {
         $shippingAddress = $address;
     }
     $saveInAddressBook = $address->getSaveInAddressBook() ? 1 : 0;
     if ($customerAddressId) {
         try {
             $addressData = $this->addressRepository->getById($customerAddressId);
         } catch (NoSuchEntityException $e) {
             // do nothing if customer is not found by id
         }
         $address = $quote->getBillingAddress()->importCustomerAddressData($addressData);
         if ($useForShipping) {
             $shippingAddress = $quote->getShippingAddress()->importCustomerAddressData($addressData);
             $shippingAddress->setSaveInAddressBook($saveInAddressBook);
         }
     } elseif ($quote->getCustomerId()) {
         $address->setEmail($quote->getCustomerEmail());
     }
     $address->setSaveInAddressBook($saveInAddressBook);
     $quote->setBillingAddress($address);
     if ($useForShipping) {
         $shippingAddress->setSameAsBilling(1);
         $shippingAddress->setCollectShippingRates(true);
         $quote->setShippingAddress($shippingAddress);
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:41,代码来源:BillingAddressPersister.php


示例2: _prepareLayout

 /**
  * Prepare the layout of the address edit block.
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     // Init address object
     if ($addressId = $this->getRequest()->getParam('id')) {
         try {
             $this->_address = $this->_addressRepository->getById($addressId);
             if ($this->_address->getCustomerId() != $this->_customerSession->getCustomerId()) {
                 $this->_address = null;
             }
         } catch (NoSuchEntityException $e) {
             $this->_address = null;
         }
     }
     if ($this->_address === null || !$this->_address->getId()) {
         $this->_address = $this->addressDataFactory->create();
         $customer = $this->getCustomer();
         $this->_address->setPrefix($customer->getPrefix());
         $this->_address->setFirstname($customer->getFirstname());
         $this->_address->setMiddlename($customer->getMiddlename());
         $this->_address->setLastname($customer->getLastname());
         $this->_address->setSuffix($customer->getSuffix());
     }
     $this->pageConfig->getTitle()->set($this->getTitle());
     if ($postedData = $this->_customerSession->getAddressFormData(true)) {
         if (!empty($postedData['region_id']) || !empty($postedData['region'])) {
             $postedData['region'] = ['region_id' => $postedData['region_id'], 'region' => $postedData['region']];
         }
         $this->dataObjectHelper->populateWithArray($this->_address, $postedData, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
     }
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:37,代码来源:Edit.php


示例3: execute

 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         /** @var  \Magento\Customer\Api\Data\CustomerInterface $customer */
         $customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
         if ($defaultShipping = $customer->getDefaultShipping()) {
             /** @var  \Magento\Customer\Model\Data\Address $address */
             $address = $this->addressRepository->getById($defaultShipping);
             if ($address) {
                 $this->_customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
             }
         }
         if ($defaultBilling = $customer->getDefaultBilling()) {
             $address = $this->addressRepository->getById($defaultBilling);
             if ($address) {
                 $this->_customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
             }
         }
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:33,代码来源:EmulateCustomerObserver.php


示例4: validate

 /**
  * Validates the fields in a specified address data object.
  *
  * @param \Magento\Quote\Api\Data\AddressInterface $addressData The address data object.
  * @return bool
  * @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer.
  * @throws \Magento\Framework\Exception\NoSuchEntityException The specified customer ID or address ID is not valid.
  */
 public function validate(\Magento\Quote\Api\Data\AddressInterface $addressData)
 {
     //validate customer id
     if ($addressData->getCustomerId()) {
         $customer = $this->customerRepository->getById($addressData->getCustomerId());
         if (!$customer->getId()) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid customer id %1', $addressData->getCustomerId()));
         }
     }
     if ($addressData->getCustomerAddressId()) {
         try {
             $this->addressRepository->getById($addressData->getCustomerAddressId());
         } catch (NoSuchEntityException $e) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getId()));
         }
         $applicableAddressIds = array_map(function ($address) {
             /** @var \Magento\Customer\Api\Data\AddressInterface $address */
             return $address->getId();
         }, $this->customerRepository->getById($addressData->getCustomerId())->getAddresses());
         if (!in_array($addressData->getCustomerAddressId(), $applicableAddressIds)) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getCustomerAddressId()));
         }
     }
     return true;
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:33,代码来源:QuoteAddressValidator.php


示例5: assign

 /**
  * {@inheritDoc}
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     if ($quote->isVirtual()) {
         throw new NoSuchEntityException(__('Cart contains virtual product(s) only. Shipping address is not applicable.'));
     }
     $saveInAddressBook = $address->getSaveInAddressBook() ? 1 : 0;
     $sameAsBilling = $address->getSameAsBilling() ? 1 : 0;
     $customerAddressId = $address->getCustomerAddressId();
     $this->addressValidator->validate($address);
     $quote->setShippingAddress($address);
     $address = $quote->getShippingAddress();
     if ($customerAddressId) {
         $addressData = $this->addressRepository->getById($customerAddressId);
         $address = $quote->getShippingAddress()->importCustomerAddressData($addressData);
     } elseif ($quote->getCustomerId()) {
         $address->setEmail($quote->getCustomerEmail());
     }
     $address->setSameAsBilling($sameAsBilling);
     $address->setSaveInAddressBook($saveInAddressBook);
     $address->setCollectShippingRates(true);
     try {
         $this->totalsCollector->collectAddressTotals($quote, $address);
         $address->save();
     } catch (\Exception $e) {
         $this->logger->critical($e);
         throw new InputException(__('Unable to save address. Please, check input data.'));
     }
     if (!$quote->validateMinimumAmount($quote->getIsMultiShipping())) {
         throw new InputException($this->scopeConfig->getValue('sales/minimum_order/error_message', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $quote->getStoreId()));
     }
     return $quote->getShippingAddress()->getId();
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:38,代码来源:ShippingAddressManagement.php


示例6: testGetAddress

 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_address.php
  * @magentoDataFixture Magento/Checkout/_files/quote_with_product_and_payment.php
  */
 public function testGetAddress()
 {
     $addressFromFixture = $this->_addressRepository->getById(self::FIXTURE_ADDRESS_ID);
     $address = $this->_block->getAddress();
     $this->assertEquals($addressFromFixture->getFirstname(), $address->getFirstname());
     $this->assertEquals($addressFromFixture->getLastname(), $address->getLastname());
     $this->assertEquals($addressFromFixture->getCustomerId(), $address->getCustomerId());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:13,代码来源:BillingTest.php


示例7: testDeleteAddress

 /**
  * @magentoApiDataFixture Magento/Customer/_files/customer.php
  * @magentoApiDataFixture Magento/Customer/_files/customer_address.php
  */
 public function testDeleteAddress()
 {
     $fixtureAddressId = 1;
     $serviceInfo = ['rest' => ['resourcePath' => "/V1/addresses/{$fixtureAddressId}", 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE], 'soap' => ['service' => self::SOAP_SERVICE_NAME, 'serviceVersion' => self::SOAP_SERVICE_VERSION, 'operation' => self::SOAP_SERVICE_NAME . 'DeleteById']];
     $requestData = ['addressId' => $fixtureAddressId];
     $response = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertTrue($response, 'Expected response should be true.');
     $this->setExpectedException('Magento\\Framework\\Exception\\NoSuchEntityException', 'No such entity with addressId = 1');
     $this->addressRepository->getById($fixtureAddressId);
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:14,代码来源:AddressRepositoryTest.php


示例8: testGetAddressCollectionJson

 public function testGetAddressCollectionJson()
 {
     $addressData = $this->_getAddresses();
     $searchResult = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressSearchResultsInterface', [], '', false, true, true, ['getItems']);
     $searchResult->expects($this->any())->method('getItems')->will($this->returnValue($addressData));
     $this->addressRepository->expects($this->any())->method('getList')->will($this->returnValue($searchResult));
     $expectedOutput = '[
         {
             "firstname": false,
             "lastname": false,
             "company": false,
             "street": "",
             "city": false,
             "country_id": "US",
             "region": false,
             "region_id": false,
             "postcode": false,
             "telephone": false,
             "fax": false,
             "vat_id": false
         },
         {
             "firstname": "FirstName1",
             "lastname": "LastName1",
             "company": false,
             "street": "Street1",
             "city": false,
             "country_id": false,
             "region": false,
             "region_id": false,
             "postcode": false,
             "telephone": false,
             "fax": false,
             "vat_id": false
         },
         {
             "firstname": "FirstName2",
             "lastname": "LastName2",
             "company": false,
             "street": "Street2",
             "city": false,
             "country_id": false,
             "region": false,
             "region_id": false,
             "postcode": false,
             "telephone": false,
             "fax": false,
             "vat_id": false
         }
     ]';
     $expectedOutput = str_replace(['    ', "\n", "\r"], '', $expectedOutput);
     $expectedOutput = str_replace(': ', ':', $expectedOutput);
     $this->assertEquals($expectedOutput, $this->_addressBlock->getAddressCollectionJson());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:54,代码来源:AddressTest.php


示例9: execute

 /**
  * @return void
  */
 public function execute()
 {
     $filter = $this->filterBuilder->setField('parent_id')->setValue($this->_getCheckout()->getCustomer()->getId())->setConditionType('eq')->create();
     $addresses = (array) $this->addressRepository->getList($this->searchCriteriaBuilder->addFilters([$filter])->create())->getItems();
     /**
      * if we create first address we need reset emd init checkout
      */
     if (count($addresses) === 1) {
         $this->_getCheckout()->reset();
     }
     $this->_redirect('*/checkout/addresses');
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:ShippingSaved.php


示例10: testGetDefaultRateRequest

 public function testGetDefaultRateRequest()
 {
     $customerDataSet = $this->customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
     $address = $this->addressRepository->getById(self::FIXTURE_ADDRESS_ID);
     $rateRequest = $this->_model->getRateRequest(null, null, null, null, $customerDataSet->getId());
     $this->assertNotNull($rateRequest);
     $this->assertEquals($address->getCountryId(), $rateRequest->getCountryId());
     $this->assertEquals($address->getRegion()->getRegionId(), $rateRequest->getRegionId());
     $this->assertEquals($address->getPostcode(), $rateRequest->getPostcode());
     $customerTaxClassId = $this->groupRepository->getById($customerDataSet->getGroupId())->getTaxClassId();
     $this->assertEquals($customerTaxClassId, $rateRequest->getCustomerClassId());
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:12,代码来源:CalculationTest.php


示例11: getAddress

 /**
  * Get a list of current customer addresses.
  *
  * @return \Magento\Customer\Api\Data\AddressInterface[]
  */
 public function getAddress()
 {
     $addresses = $this->getData('address_collection');
     if ($addresses === null) {
         try {
             $filter = $this->filterBuilder->setField('parent_id')->setValue($this->_multishipping->getCustomer()->getId())->setConditionType('eq')->create();
             $addresses = (array) $this->addressRepository->getList($this->searchCriteriaBuilder->addFilters([$filter])->create())->getItems();
         } catch (NoSuchEntityException $e) {
             return [];
         }
         $this->setData('address_collection', $addresses);
     }
     return $addresses;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:Select.php


示例12: testPopulateCustomerInfo

 public function testPopulateCustomerInfo()
 {
     $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($this->customerMock);
     $this->customerMock->expects($this->atLeastOnce())->method('getId')->willReturn(null);
     $this->customerMock->expects($this->atLeastOnce())->method('getDefaultBilling')->willReturn(100500);
     $this->quoteMock->expects($this->atLeastOnce())->method('getBillingAddress')->willReturn($this->quoteAddressMock);
     $this->quoteMock->expects($this->atLeastOnce())->method('getShippingAddress')->willReturn($this->quoteAddressMock);
     $this->quoteMock->expects($this->atLeastOnce())->method('setCustomer')->with($this->customerMock)->willReturnSelf();
     $this->quoteMock->expects($this->once())->method('getPasswordHash')->willReturn('password hash');
     $this->quoteAddressMock->expects($this->atLeastOnce())->method('getId')->willReturn(null);
     $this->customerAddressRepositoryMock->expects($this->atLeastOnce())->method('getById')->with(100500)->willReturn($this->customerAddressMock);
     $this->quoteAddressMock->expects($this->atLeastOnce())->method('importCustomerAddressData')->willReturnSelf();
     $this->accountManagementMock->expects($this->once())->method('createAccountWithPasswordHash')->with($this->customerMock, 'password hash')->willReturn($this->customerMock);
     $this->customerManagement->populateCustomerInfo($this->quoteMock);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:CustomerManagementTest.php


示例13: testSetLayoutWithoutAddress

 public function testSetLayoutWithoutAddress()
 {
     $addressId = 1;
     $customerPrefix = 'prefix';
     $customerFirstName = 'firstname';
     $customerMiddlename = 'middlename';
     $customerLastname = 'lastname';
     $customerSuffix = 'suffix';
     $title = 'title';
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->getMock();
     $this->requestMock->expects($this->once())->method('getParam')->with('id', null)->willReturn($addressId);
     $this->addressRepositoryMock->expects($this->once())->method('getById')->with($addressId)->willThrowException(\Magento\Framework\Exception\NoSuchEntityException::singleField('addressId', $addressId));
     $newAddressMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->getMock();
     $this->addressDataFactoryMock->expects($this->once())->method('create')->willReturn($newAddressMock);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $this->currentCustomerMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
     $customerMock->expects($this->once())->method('getPrefix')->willReturn($customerPrefix);
     $customerMock->expects($this->once())->method('getFirstname')->willReturn($customerFirstName);
     $customerMock->expects($this->once())->method('getMiddlename')->willReturn($customerMiddlename);
     $customerMock->expects($this->once())->method('getLastname')->willReturn($customerLastname);
     $customerMock->expects($this->once())->method('getSuffix')->willReturn($customerSuffix);
     $newAddressMock->expects($this->once())->method('setPrefix')->with($customerPrefix)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setFirstname')->with($customerFirstName)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setMiddlename')->with($customerMiddlename)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setLastname')->with($customerLastname)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setSuffix')->with($customerSuffix)->willReturnSelf();
     $pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock();
     $this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($pageTitleMock);
     $this->model->setData('title', $title);
     $pageTitleMock->expects($this->once())->method('set')->with($title)->willReturnSelf();
     $this->assertEquals($this->model, $this->model->setLayout($layoutMock));
     $this->assertEquals($layoutMock, $this->model->getLayout());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:33,代码来源:EditTest.php


示例14: testSearchAddresses

 /**
  * @param \Magento\Framework\Api\Filter[] $filters
  * @param \Magento\Framework\Api\Filter[] $filterGroup
  * @param \Magento\Framework\Api\SortOrder[] $filterOrders
  * @param array $expectedResult array of expected results indexed by ID
  *
  * @dataProvider searchAddressDataProvider
  *
  * @magentoDataFixture  Magento/Customer/_files/customer.php
  * @magentoDataFixture  Magento/Customer/_files/customer_two_addresses.php
  * @magentoAppIsolation enabled
  */
 public function testSearchAddresses($filters, $filterGroup, $filterOrders, $expectedResult)
 {
     /** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchBuilder */
     $searchBuilder = $this->_objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
     foreach ($filters as $filter) {
         $searchBuilder->addFilters([$filter]);
     }
     if ($filterGroup !== null) {
         $searchBuilder->addFilters($filterGroup);
     }
     if ($filterOrders !== null) {
         foreach ($filterOrders as $order) {
             $searchBuilder->addSortOrder($order);
         }
     }
     $searchResults = $this->repository->getList($searchBuilder->create());
     $this->assertEquals(count($expectedResult), $searchResults->getTotalCount());
     $i = 0;
     /** @var \Magento\Customer\Api\Data\AddressInterface $item*/
     foreach ($searchResults->getItems() as $item) {
         $this->assertEquals($expectedResult[$i]['id'], $item->getId());
         $this->assertEquals($expectedResult[$i]['city'], $item->getCity());
         $this->assertEquals($expectedResult[$i]['postcode'], $item->getPostcode());
         $this->assertEquals($expectedResult[$i]['firstname'], $item->getFirstname());
         $i++;
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:39,代码来源:AddressRepositoryTest.php


示例15: testExecuteWithException

 public function testExecuteWithException()
 {
     $addressId = 1;
     $customerId = 2;
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->request->expects($this->once())->method('getParam')->with('id', false)->willReturn($addressId);
     $this->validatorMock->expects($this->once())->method('validate')->with($this->request)->willReturn(true);
     $this->addressRepositoryMock->expects($this->once())->method('getById')->with($addressId)->willReturn($this->address);
     $this->sessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->address->expects($this->once())->method('getCustomerId')->willReturn(34);
     $exception = new \Exception('Exception');
     $this->messageManager->expects($this->once())->method('addError')->with(__('We can\'t delete the address right now.'))->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addException')->with($exception, __('We can\'t delete the address right now.'));
     $this->resultRedirect->expects($this->once())->method('setPath')->with('*/*/index')->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->model->execute());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:16,代码来源:DeleteTest.php


示例16: testSaveActionExistingCustomerAndExistingAddressData

 /**
  * @magentoDataFixture Magento/Customer/_files/customer_sample.php
  */
 public function testSaveActionExistingCustomerAndExistingAddressData()
 {
     $post = ['customer' => ['entity_id' => '1', 'middlename' => 'test middlename', 'group_id' => 1, 'website_id' => 1, 'firstname' => 'test firstname', 'lastname' => 'test lastname', 'email' => '[email protected]', 'new_password' => 'auto', 'sendemail_store_id' => '1', 'sendemail' => '1', 'created_at' => '2000-01-01 00:00:00', 'default_shipping' => '_item1', 'default_billing' => 1], 'address' => ['1' => ['firstname' => 'update firstname', 'lastname' => 'update lastname', 'street' => ['update street'], 'city' => 'update city', 'region_id' => 10, 'country_id' => 'US', 'postcode' => '01001', 'telephone' => '+7000000001', 'default_billing' => 'true'], '_item1' => ['firstname' => 'new firstname', 'lastname' => 'new lastname', 'street' => ['new street'], 'city' => 'new city', 'region_id' => 10, 'country_id' => 'US', 'postcode' => '01001', 'telephone' => '+7000000001', 'default_shipping' => 'true'], '_template_' => ['firstname' => '', 'lastname' => '', 'street' => [], 'city' => '', 'region_id' => 10, 'country_id' => 'US', 'postcode' => '', 'telephone' => '']], 'subscription' => ''];
     $this->getRequest()->setPostValue($post);
     $this->getRequest()->setParam('id', 1);
     $this->dispatch('backend/customer/index/save');
     /** Check that success message is set */
     $this->assertSessionMessages($this->equalTo(['You saved the customer.']), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS);
     /** Check that customer id set and addresses saved */
     $registry = $this->objectManager->get('Magento\\Framework\\Registry');
     $customerId = $registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
     $customer = $this->customerRepository->getById($customerId);
     $this->assertEquals('test firstname', $customer->getFirstname());
     /**
      * Addresses should be removed by
      * \Magento\Customer\Model\ResourceModel\Customer::_saveAddresses during _afterSave
      * addressOne - updated
      * addressTwo - removed
      * addressThree - removed
      * _item1 - new address
      */
     $addresses = $customer->getAddresses();
     $this->assertEquals(2, count($addresses));
     $updatedAddress = $this->addressRepository->getById(1);
     $this->assertEquals('update firstname', $updatedAddress->getFirstname());
     $newAddress = $this->accountManagement->getDefaultShippingAddress($customerId);
     $this->assertEquals('new firstname', $newAddress->getFirstname());
     /** @var \Magento\Newsletter\Model\Subscriber $subscriber */
     $subscriber = $this->objectManager->get('Magento\\Newsletter\\Model\\SubscriberFactory')->create();
     $this->assertEmpty($subscriber->getId());
     $subscriber->loadByCustomerId($customerId);
     $this->assertNotEmpty($subscriber->getId());
     $this->assertEquals(1, $subscriber->getStatus());
     $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'index/key/'));
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:38,代码来源:IndexTest.php


示例17: testCreateAccountWithPasswordHashWithCustomerAddresses

 public function testCreateAccountWithPasswordHashWithCustomerAddresses()
 {
     $websiteId = 1;
     $addressId = 2;
     $customerId = null;
     $storeId = 1;
     $hash = '4nj54lkj5jfi03j49f8bgujfgsd';
     //Handle store
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $store->expects($this->any())->method('getWebsiteId')->willReturn($websiteId);
     //Handle address - existing and non-existing. Non-Existing should return null when call getId method
     $existingAddress = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
     $nonExistingAddress = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
     //Ensure that existing address is not in use
     $this->addressRepository->expects($this->atLeastOnce())->method("save")->withConsecutive(array($this->logicalNot($this->identicalTo($existingAddress))), array($this->identicalTo($nonExistingAddress)));
     $existingAddress->expects($this->any())->method("getId")->willReturn($addressId);
     //Expects that id for existing address should be unset
     $existingAddress->expects($this->once())->method("setId")->with(null);
     //Handle Customer calls
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customer->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn($websiteId);
     $customer->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId);
     $customer->expects($this->any())->method("getId")->willReturn($customerId);
     //Return Customer from customer repositoryå
     $this->customerRepository->expects($this->atLeastOnce())->method('save')->willReturn($customer);
     $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
     $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock();
     $customerSecure->expects($this->once())->method('setRpToken')->with($hash);
     $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($hash);
     $this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure);
     $this->random->expects($this->once())->method('getUniqueHash')->willReturn($hash);
     $customer->expects($this->atLeastOnce())->method('getAddresses')->willReturn([$existingAddress, $nonExistingAddress]);
     $this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($store);
     $this->assertSame($customer, $this->accountManagement->createAccountWithPasswordHash($customer, $hash));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:35,代码来源:AccountManagementTest.php


示例18: testGetCustomerDefaultAddressDefaultAddressNotSet

 /**
  * Test case when customer has addresses, but default {$addressType} address is not set.
  *
  * @param string $addressType
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
  * @magentoAppIsolation enabled
  * @dataProvider getCustomerDefaultAddressDataProvider
  */
 public function testGetCustomerDefaultAddressDefaultAddressNotSet($addressType)
 {
     /**
      * Preconditions:
      * - customer has addresses, but default address of {$addressType} is not set
      * - current customer is set to customer session
      */
     $fixtureCustomerId = 1;
     $firstFixtureAddressId = 1;
     $firstFixtureAddressStreet = ['Green str, 67'];
     /** @var \Magento\Customer\Model\Customer $customer */
     $customer = Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Customer')->load($fixtureCustomerId);
     if ($addressType == self::ADDRESS_TYPE_SHIPPING) {
         $customer->setDefaultShipping(null)->save();
     } else {
         // billing
         $customer->setDefaultBilling(null)->save();
     }
     /** @var \Magento\Customer\Model\Session $customerSession */
     $customerSession = Bootstrap::getObjectManager()->get('Magento\\Customer\\Model\\Session');
     $customerSession->setCustomer($customer);
     /** Execute SUT */
     if ($addressType == self::ADDRESS_TYPE_SHIPPING) {
         $addressId = $this->_multishippingCheckout->getCustomerDefaultShippingAddress();
     } else {
         // billing
         $addressId = $this->_multishippingCheckout->getCustomerDefaultBillingAddress();
     }
     $address = $this->addressRepository->getById($addressId);
     $this->assertInstanceOf('\\Magento\\Customer\\Api\\Data\\AddressInterface', $address, "Address was not loaded.");
     $this->assertEquals($firstFixtureAddressId, $address->getId(), "Invalid address loaded.");
     $this->assertEquals($firstFixtureAddressStreet, $address->getStreet(), "Street in default {$addressType} address is invalid.");
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:42,代码来源:MultishippingTest.php


示例19: getAddressById

 /**
  * @param int $addressId
  * @return \Magento\Customer\Api\Data\AddressInterface|null
  */
 public function getAddressById($addressId)
 {
     try {
         return $this->addressRepository->getById($addressId);
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return null;
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:Book.php


示例20: testSaveBilling

 /**
  * @dataProvider saveBillingDataProvider
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function testSaveBilling($data, $customerAddressId, $quoteCustomerId, $addressCustomerId, $isAddress, $validateDataResult, $validateResult, $checkoutMethod, $customerPassword, $confirmPassword, $validationResultMessages, $isEmailAvailable, $isVirtual, $getStepDataResult, $expected)
 {
     $useForShipping = (int) $data['use_for_shipping'];
     $passwordHash = 'password hash';
     $this->requestMock->expects($this->any())->method('isAjax')->will($this->returnValue(false));
     $customerValidationResultMock = $this->getMock('Magento\\Customer\\Api\\Data\\ValidationResultsInterface', [], [], '', false);
     $customerValidationResultMock->expects($this->any())->method('isValid')->will($this->returnValue(empty($validationResultMessages)));
     $customerValidationResultMock->expects($this->any())->method('getMessages')->will($this->returnValue($validationResultMessages));
     $this->accountManagementMock->expects($this->any())->method('getPasswordHash')->with($customerPassword)->will($this->returnValue($passwordHash));
     $this->accountManagementMock->expects($this->any())->method('validate')->will($this->returnValue($customerValidationResultMock));
     $this->accountManagementMock->expects($this->any())->method('isEmailAvailable')->will($this->returnValue($isEmailAvailable));
     /** @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject $quoteMock */
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['getData', 'getCustomerId', '__wakeup', 'getBillingAddress', 'setPasswordHash', 'getCheckoutMethod', 'isVirtual', 'getShippingAddress', 'getCustomerData', 'collectTotals', 'save', 'getCustomer'], [], '', false);
     $customerMock = $this->getMockForAbstractClass('Magento\\Framework\\Api\\AbstractExtensibleObject', [], '', false, true, true, ['__toArray']);
     $shippingAddressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['setSameAsBilling', 'save', 'collectTotals', 'addData', 'setShippingMethod', 'setCollectShippingRates', '__wakeup'], [], '', false);
     $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock));
     $shippingAddressMock->expects($useForShipping ? $this->any() : $this->once())->method('setSameAsBilling')->with($useForShipping)->will($this->returnSelf());
     $expects = !$useForShipping || $checkoutMethod != Onepage::METHOD_REGISTER ? $this->once() : $this->never();
     $shippingAddressMock->expects($expects)->method('save');
     $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('addData')->will($this->returnSelf());
     $shippingAddressMock->expects($this->any())->method('setSaveInAddressBook')->will($this->returnSelf());
     $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('setShippingMethod')->will($this->returnSelf());
     $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('setCollectShippingRates')->will($this->returnSelf());
     $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('collectTotals');
     $quoteMock->expects($this->any())->method('setPasswordHash')->with($passwordHash);
     $quoteMock->expects($this->any())->method('getCheckoutMethod')->will($this->returnValue($checkoutMethod));
     $quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue($isVirtual));
     $addressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['setSaveInAddressBook', 'getData', 'setEmail', '__wakeup', 'importCustomerAddressData', 'validate', 'save'], [], '', false);
     $addressMock->expects($this->any())->method('importCustomerAddressData')->will($this->returnSelf());
     $addressMock->expects($this-&g 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Api\CustomerRepositoryInterface类代码示例发布时间:2022-05-23
下一篇:
PHP Api\AccountManagementInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap