当前位置: 首页>>代码示例>>PHP>>正文


PHP AddressRepositoryInterface::save方法代码示例

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


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

示例1: iAddTheAddressToMyAddressBook

 /**
  * @When I add the address to my address book
  */
 public function iAddTheAddressToMyAddressBook()
 {
     try {
         $this->customerAddress = $this->addressRepository->save($this->customerAddress);
         $this->saveAddressException = null;
     } catch (LocalizedException $e) {
         $this->saveAddressException = $e;
     }
 }
开发者ID:eBayEnterprise,项目名称:magento2-retail-order-management,代码行数:12,代码来源:IntegrationContext.php

示例2: testSaveAddressesCustomerIdInvalid

 public function testSaveAddressesCustomerIdInvalid()
 {
     $proposedAddress = $this->_createSecondAddress()->setCustomerId('this_is_not_a_valid_id');
     try {
         $this->repository->save($proposedAddress);
         $this->fail('Expected exception not thrown');
     } catch (NoSuchEntityException $nsee) {
         $this->assertEquals('No such entity with customerId = this_is_not_a_valid_id', $nsee->getMessage());
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:AddressRepositoryTest.php

示例3: aroundSaveAddressInformation

 /**
  *Set additional information for shipping address
  *
  * @param \Magento\Checkout\Model\ShippingInformationManagement $subject
  * @param callable $proceed
  *
  * @return \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function aroundSaveAddressInformation(\Magento\Checkout\Model\ShippingInformationManagement $subject, $proceed, $cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation)
 {
     try {
         $carrierCode = $addressInformation->getShippingCarrierCode();
         $methodCode = $addressInformation->getShippingMethodCode();
         $shippingMethod = $carrierCode . '_' . $methodCode;
         $quote = $this->quoteRepository->getActive($cartId);
         $address = $quote->getShippingAddress();
         $validation = $this->checkoutSession->getShipAddressValidation();
         if (is_array($validation) && isset($validation['key'])) {
             if (isset($validation['validation_status'])) {
                 $additionalDetail['address_valid'] = $validation['validation_status'];
                 $address->setValidationStatus($validation['validation_status']);
             }
             if (isset($validation['destination_type'])) {
                 $additionalDetail['destination_type'] = $validation['destination_type'];
                 $address->setDestinationType($validation['destination_type']);
             }
             $this->checkoutSession->setShipAddressValidation(null);
         }
         $address->save();
         $additionalDetail = new \Magento\Framework\DataObject();
         $extAttributes = $addressInformation->getShippingAddress()->getExtensionAttributes();
         //push out event so other modules can save their data TODO add carrier_group_id
         $this->eventManager->dispatch('shipperhq_additional_detail_checkout', ['address_extn_attributes' => $extAttributes, 'additional_detail' => $additionalDetail, 'carrier_code' => $carrierCode]);
         $additionalDetailArray = $additionalDetail->convertToArray();
         $this->shipperLogger->postDebug('ShipperHQ Shipper', 'processing additional detail ', $additionalDetail);
         $this->carrierGroupHelper->saveCarrierGroupInformation($address, $shippingMethod, $additionalDetailArray);
     } catch (\Exception $e) {
         $this->shipperLogger->postCritical('Shipperhq_Shipper', 'Shipping Information Plugin', 'Exception raised ' . $e->getMessage());
     }
     $result = $proceed($cartId, $addressInformation);
     if ($address->getCustomerId()) {
         $customerAddresses = $quote->getCustomer()->getAddresses();
         foreach ($customerAddresses as $oneAddress) {
             if ($oneAddress->getId() == $address->getCustomerAddressId()) {
                 if ($address->getValidationStatus()) {
                     $oneAddress->setCustomAttribute('validation_status', $address->getValidationStatus());
                 }
                 if ($address->getDestinationType()) {
                     $oneAddress->setCustomAttribute('destination_type', $address->getDestinationType());
                 }
                 $this->addressRepository->save($oneAddress);
             }
         }
     }
     return $result;
 }
开发者ID:shipperhq,项目名称:module-shipper,代码行数:57,代码来源:ShippingInformationPlugin.php

示例4: createAccountWithPasswordHash

 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function createAccountWithPasswordHash(CustomerInterface $customer, $hash, $redirectUrl = '')
 {
     // This logic allows an existing customer to be added to a different store.  No new account is created.
     // The plan is to move this logic into a new method called something like 'registerAccountWithStore'
     if ($customer->getId()) {
         $customer = $this->customerRepository->get($customer->getEmail());
         $websiteId = $customer->getWebsiteId();
         if ($this->isCustomerInStore($websiteId, $customer->getStoreId())) {
             throw new InputException(__('This customer already exists in this store.'));
         }
         // Existing password hash will be used from secured customer data registry when saving customer
     }
     // Make sure we have a storeId to associate this customer with.
     if (!$customer->getStoreId()) {
         if ($customer->getWebsiteId()) {
             $storeId = $this->storeManager->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
         } else {
             $storeId = $this->storeManager->getStore()->getId();
         }
         $customer->setStoreId($storeId);
     }
     // Update 'created_in' value with actual store name
     if ($customer->getId() === null) {
         $storeName = $this->storeManager->getStore($customer->getStoreId())->getName();
         $customer->setCreatedIn($storeName);
     }
     $customerAddresses = $customer->getAddresses() ?: [];
     $customer->setAddresses(null);
     try {
         // If customer exists existing hash will be used by Repository
         $customer = $this->customerRepository->save($customer, $hash);
     } catch (AlreadyExistsException $e) {
         throw new InputMismatchException(__('A customer with the same email already exists in an associated website.'));
     } catch (LocalizedException $e) {
         throw $e;
     }
     try {
         foreach ($customerAddresses as $address) {
             $address->setCustomerId($customer->getId());
             $this->addressRepository->save($address);
         }
     } catch (InputException $e) {
         $this->customerRepository->delete($customer);
         throw $e;
     }
     $customer = $this->customerRepository->getById($customer->getId());
     $newLinkToken = $this->mathRandom->getUniqueHash();
     $this->changeResetPasswordLinkToken($customer, $newLinkToken);
     $this->sendEmailConfirmation($customer, $redirectUrl);
     return $customer;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:56,代码来源:AccountManagement.php

示例5: aroundSaveAddressInformation

 public function aroundSaveAddressInformation(\Magento\Checkout\Model\ShippingInformationManagement $subject, \Closure $proceed, $cartId, ShippingInformationInterface $addressInformation)
 {
     // Only validate address if module is enabled
     $quote = $this->quoteRepository->getActive($cartId);
     $storeId = $quote->getStoreId();
     if (!$this->config->isModuleEnabled($storeId)) {
         $paymentDetails = $proceed($cartId, $addressInformation);
         $this->ensureTaxCalculationSuccess($storeId);
         return $paymentDetails;
     }
     // Only validate address if address validation is enabled
     if (!$this->config->isAddressValidationEnabled($storeId)) {
         $paymentDetails = $proceed($cartId, $addressInformation);
         $this->ensureTaxCalculationSuccess($storeId);
         return $paymentDetails;
     }
     // If quote is virtual, getShippingAddress will return billing address, so no need to check if quote is virtual
     $shippingAddress = $addressInformation->getShippingAddress();
     $shippingInformationExtension = $addressInformation->getExtensionAttributes();
     $errorMessage = null;
     $validAddress = null;
     $customerAddress = null;
     $quoteAddress = null;
     $shouldValidateAddress = true;
     if (!is_null($shippingInformationExtension)) {
         $shouldValidateAddress = $shippingInformationExtension->getShouldValidateAddress();
     }
     $customerAddressId = $shippingAddress->getCustomerAddressId();
     $enabledAddressValidationCountries = explode(',', $this->config->getAddressValidationCountriesEnabled($storeId));
     if (!in_array($shippingAddress->getCountryId(), $enabledAddressValidationCountries)) {
         $shouldValidateAddress = false;
     }
     if ($shouldValidateAddress) {
         try {
             $validAddress = $this->validationInteraction->validateAddress($shippingAddress, $storeId);
         } catch (AddressValidateException $e) {
             $errorMessage = $e->getMessage();
         } catch (\SoapFault $e) {
             // If there is a SoapFault, it will have already been logged, so just disable address validation, as we
             // don't want to display SoapFault error message to user
             $shouldValidateAddress = false;
         } catch (\Exception $e) {
             $this->avaTaxLogger->error('Error in validating address in aroundSaveAddressInformation: ' . $e->getMessage());
             // Continue without address validation
             $shouldValidateAddress = false;
         }
     }
     // Determine which address to save to the customer or shipping addresses
     if (!is_null($validAddress)) {
         $quoteAddress = $validAddress;
     } else {
         $quoteAddress = $shippingAddress;
     }
     try {
         /*
          * Regardless of whether address was validated by AvaTax, if the address is a customer address then we need
          * to save that address on the customer record. The reason for this is that when a user is on the "Review
          * & Payments" step and they are selecting between "Valid" and "Original" address options, the selected
          * address information is submitted to this API so that the customer address is updated and tax
          * calculation is affected accordingly.
          */
         if ($customerAddressId) {
             // Update the customer address
             $customerAddress = $this->customerAddressRepository->getById($customerAddressId);
             $mergedCustomerAddress = $this->addressInteraction->copyQuoteAddressToCustomerAddress($quoteAddress, $customerAddress);
             $this->customerAddressRepository->save($mergedCustomerAddress);
         } else {
             // Update the shipping address
             $addressInformation->setShippingAddress($quoteAddress);
         }
     } catch (\Exception $e) {
         // There may be scenarios in which the above address updating may fail, in which case we should just do
         // nothing
         $this->avaTaxLogger->error('Error in saving address: ' . $e->getMessage());
         // Continue without address validation
         $shouldValidateAddress = false;
     }
     $returnValue = $proceed($cartId, $addressInformation);
     $this->ensureTaxCalculationSuccess($storeId);
     if (!$shouldValidateAddress) {
         return $returnValue;
     }
     $paymentDetailsExtension = $returnValue->getExtensionAttributes();
     if (is_null($paymentDetailsExtension)) {
         $paymentDetailsExtension = $this->paymentDetailsExtensionFactory->create();
     }
     if (!is_null($validAddress)) {
         $paymentDetailsExtension->setValidAddress($validAddress);
     } else {
         $paymentDetailsExtension->setErrorMessage($errorMessage);
     }
     $paymentDetailsExtension->setOriginalAddress($shippingAddress);
     $returnValue->setExtensionAttributes($paymentDetailsExtension);
     return $returnValue;
 }
开发者ID:classyllama,项目名称:ClassyLlama_AvaTax,代码行数:95,代码来源:ShippingInformationManagement.php


注:本文中的Magento\Customer\Api\AddressRepositoryInterface::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。