當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Session::getShipAddressValidation方法代碼示例

本文整理匯總了PHP中Magento\Checkout\Model\Session::getShipAddressValidation方法的典型用法代碼示例。如果您正苦於以下問題:PHP Session::getShipAddressValidation方法的具體用法?PHP Session::getShipAddressValidation怎麽用?PHP Session::getShipAddressValidation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Checkout\Model\Session的用法示例。


在下文中一共展示了Session::getShipAddressValidation方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: setRequest

 /**
  * Prepare and set request to this instance
  *
  * @param \Magento\Quote\Model\Quote\Address\RateRequest $request
  * @return $this
  */
 public function setRequest(\Magento\Quote\Model\Quote\Address\RateRequest $request)
 {
     if (is_array($request->getAllItems())) {
         $item = current($request->getAllItems());
         if ($item instanceof QuoteItem) {
             $request->setQuote($item->getQuote());
             $this->quote = $item->getQuote();
         }
     }
     //SHQ16-1261 - further detail as values not on shipping address
     if (!$this->quote) {
         $this->quote = $this->shipperDataHelper->getQuote();
     }
     $shippingAddress = $this->quote->getShippingAddress();
     $key = $this->shipperDataHelper->getAddressKey($shippingAddress);
     $existing = $this->checkoutSession->getShipAddressValidation();
     $validate = true;
     if (is_array($existing)) {
         if (isset($existing['key']) && $existing['key'] == $key) {
             $validate = false;
         }
     } else {
         $validate = $this->shipperRateHelper->shouldValidateAddress($shippingAddress->getValidationStatus(), $shippingAddress->getDestinationType());
     }
     $request->setValidateAddress($validate);
     $request->setSelectedOptions($this->getSelectedOptions($shippingAddress));
     $isCheckout = $this->shipperDataHelper->isCheckout($this->quote);
     $cartType = !is_null($isCheckout) && $isCheckout != 1 ? "CART" : "STD";
     if ($this->quote->getIsMultiShipping()) {
         $cartType = 'MAC';
     }
     $request->setCartType($cartType);
     $this->eventManager->dispatch('shipperhq_carrier_set_request', ['request' => $request]);
     $this->shipperRequest = $this->shipperMapper->getShipperTranslation($request);
     $this->rawRequest = $request;
     return $this;
 }
開發者ID:shipperhq,項目名稱:module-shipper,代碼行數:43,代碼來源:Shipper.php


注:本文中的Magento\Checkout\Model\Session::getShipAddressValidation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。