Skip to content

Commit

Permalink
20.4.5 SHQ16-2178 set address type on new quote
Browse files Browse the repository at this point in the history
  • Loading branch information
wsajason committed Aug 11, 2017
1 parent 494c7e0 commit 7aeb9f6
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 65 deletions.
287 changes: 227 additions & 60 deletions CHANGELOG.MD

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Model/Carrier/Shipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function setRequest(\Magento\Quote\Model\Quote\Address\RateRequest $reque

$existing = $this->getExistingValidation($key); //SHQ16-1902
$validate = true;
if (is_array($existing)) {
if (is_array($existing) && count($existing) > 0) {
if (isset($existing['key']) && $existing['key'] == $key) {
$validate = false;
}
Expand Down
1 change: 1 addition & 0 deletions src/Plugin/Checkout/ShippingInformationPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function aroundSaveAddressInformation(
$extAttributes = $addressInformation->getShippingAddress()->getExtensionAttributes();

//push out event so other modules can save their data - in future add carrier_group_id
//Observers add to additionalDetail object
$this->eventManager->dispatch(
'shipperhq_additional_detail_checkout',
['address_extn_attributes' => $extAttributes, 'additional_detail'=> $additionalDetail,
Expand Down
99 changes: 99 additions & 0 deletions src/Plugin/Quote/ShippingMethodManagementPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
*
* ShipperHQ Shipping Module
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* Shipper HQ Shipping
*
* @category ShipperHQ
* @package ShipperHQ_Shipping_Carrier
* @copyright Copyright (c) 2015 Zowta LLC (http://www.ShipperHQ.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author ShipperHQ Team sales@shipperhq.com
*/
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace ShipperHQ\Shipper\Plugin\Quote;

class ShippingMethodManagementPlugin
{
/**
* Quote repository.
*
* @var \Magento\Quote\Api\CartRepositoryInterface
*/
protected $quoteRepository;
/**
* @var \ShipperHQ\Shipper\Helper\LogAssist
*/
private $shipperLogger;
/**
* Customer Address repository
*
* @var \Magento\Customer\Api\AddressRepositoryInterface
*/
private $addressRepository;

public function __construct(
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
\ShipperHQ\Shipper\Helper\LogAssist $shipperLogger,
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
) {
$this->quoteRepository = $quoteRepository;
$this->shipperLogger = $shipperLogger;
$this->addressRepository = $addressRepository;

}

/**
*Add customers address type to shipping address on quote
*
* @param \Magento\Quote\Model\ShippingMethodManagement $subject
* @param callable $proceed
* @param $cartId
* @param int $addressId
* @return \Magento\Quote\Api\Data\ShippingMethodInterface[]
*
*/
public function aroundEstimateByAddressId(\Magento\Quote\Model\ShippingMethodManagement $subject, $proceed, $cartId, $addressId)
{
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->quoteRepository->getActive($cartId);

// no methods applicable for empty carts or carts with virtual products
if ($quote->isVirtual() || 0 == $quote->getItemsCount()) {
return $proceed($cartId, $addressId);
}
$address = $this->addressRepository->getById($addressId);

if($custom = $address->getCustomAttributes()) {
foreach ($custom as $custom_attribute) {
if($custom_attribute->getAttributeCode() == 'destination_type') {
$quote->getShippingAddress()->setData('destination_type', $custom_attribute->getValue());
} elseif ($custom_attribute->getAttributeCode() == 'validation_status') {
$quote->getShippingAddress()->setData('validation_status', $custom_attribute->getValue());
}
}
}

return $proceed($cartId, $addressId);
}
}
6 changes: 3 additions & 3 deletions src/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
$this->installAttributes($catalogSetup);
}
//v 1.0.3
if ($context->getVersion() && version_compare($context->getVersion(), '1.0.3') < 0) {
if (version_compare($context->getVersion(), '1.0.3') < 0) {
$catalogSetup->addAttribute(\Magento\Catalog\Model\Product::ENTITY, 'shipperhq_availability_date', [
'type' => 'datetime',
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\Datetime',
Expand All @@ -134,7 +134,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
$salesSetup = $this->salesSetupFactory->create(['setup' => $setup]);
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

if ($context->getVersion() && version_compare($context->getVersion(), '1.0.5') < 0) {
if (version_compare($context->getVersion(), '1.0.5') < 0) {

$destinationTypeAttr = [
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
Expand Down Expand Up @@ -192,7 +192,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
}

//1.0.7
if ($context->getVersion() && version_compare($context->getVersion(), '1.0.7') < 0) {
if (version_compare($context->getVersion(), '1.0.7') < 0) {
$dispatchDateAttr = [
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATE,
'visible' => false,
Expand Down
2 changes: 1 addition & 1 deletion src/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
<ws_timeout>30</ws_timeout>
<use_cache>0</use_cache>
<extension_version>20.5.9</extension_version>
<extension_version>#GIT_TAG#</extension_version>
<allowed_methods></allowed_methods>
</shipper>
<shipperadmin>
Expand Down
6 changes: 6 additions & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@
<argument name="checkoutSession" xsi:type="object">Magento\Checkout\Model\Session\Proxy</argument>
</arguments>
</type>
<type name="Magento\Quote\Model\ShippingMethodManagement">
<plugin name="shipperhq_shipper_plugin_quote_shipping_method_management"
type="ShipperHQ\Shipper\Plugin\Quote\ShippingMethodManagementPlugin"
sortOrder="10"
disabled="false"/>
</type>
</config>

0 comments on commit 7aeb9f6

Please sign in to comment.