Skip to content

Commit

Permalink
SHQ16-2024 refactored checkout shipping information plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
wsagen committed Apr 24, 2017
1 parent 5339e9d commit 6382fb1
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions src/Plugin/Checkout/ShippingInformationPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,46 +107,47 @@ public function aroundSaveAddressInformation(\Magento\Checkout\Model\ShippingInf
$cartId,
\Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation)
{
$carrierCode = $addressInformation->getShippingCarrierCode();
$methodCode = $addressInformation->getShippingMethodCode();
$shippingMethod = $carrierCode . '_' . $methodCode;
$quote = $this->quoteRepository->getActive($cartId);
$address = $quote->getShippingAddress();

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']);
if($this->checkoutSession) {
$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);
}
$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);
$result = $proceed($cartId, $addressInformation);

$this->carrierGroupHelper->saveCarrierGroupInformation($address,
$shippingMethod, $additionalDetailArray);

} catch (\Exception $e) {
$this->shipperLogger->postCritical('Shipperhq_Shipper',
'Shipping Information Plugin',
'Exception raised ' .$e->getMessage());
}

$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);
$result = $proceed($cartId, $addressInformation);

$this->carrierGroupHelper->saveCarrierGroupInformation($address,
$shippingMethod, $additionalDetailArray);

if($address->getCustomerId()) {
$customerAddresses = $quote->getCustomer()->getAddresses();
Expand Down

0 comments on commit 6382fb1

Please sign in to comment.