-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from mygento/rate-ext-attributes
Rate ext attributes
- Loading branch information
Showing
7 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* @author Mygento | ||
* @copyright 2017 Mygento (https://www.mygento.ru) | ||
* @package Mygento_Shipment | ||
*/ | ||
|
||
namespace Mygento\Shipment\Plugin; | ||
|
||
class ExtRate | ||
{ | ||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterImportShippingRate( | ||
\Magento\Quote\Model\Quote\Address\Rate $subject, | ||
$result, | ||
\Magento\Quote\Model\Quote\Address\RateResult\AbstractResult $rate | ||
) { | ||
$result->setEstimate($rate->getEstimate()); | ||
$result->setLatitude($rate->getLatitude()); | ||
$result->setLongitude($rate->getLongitude()); | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* @author Mygento | ||
* @copyright 2017 Mygento (https://www.mygento.ru) | ||
* @package Mygento_Shipment | ||
*/ | ||
|
||
namespace Mygento\Shipment\Plugin; | ||
|
||
class ExtShippingMethodManagement | ||
{ | ||
protected $shippingExtAttr; | ||
|
||
public function __construct( | ||
\Magento\Quote\Api\Data\ShippingMethodExtensionFactory $shippingExtAttr | ||
) { | ||
$this->shippingExtAttr = $shippingExtAttr; | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterModelToDataObject( | ||
\Magento\Quote\Model\Cart\ShippingMethodConverter $subject, | ||
$result, | ||
\Magento\Quote\Model\Quote\Address\Rate $rateModel | ||
) { | ||
$extensionAttributes = | ||
$result->getExtensionAttributes() | ||
?? $this->shippingExtAttr->create(); | ||
$extensionAttributes->setEstimate($rateModel->getEstimate()); | ||
$extensionAttributes->setLatitude($rateModel->getLatitude()); | ||
$extensionAttributes->setLongitude($rateModel->getLongitude()); | ||
$result->setExtensionAttributes($extensionAttributes); | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* @author Mygento | ||
* @copyright 2017 Mygento (https://www.mygento.ru) | ||
* @package Mygento_Shipment | ||
*/ | ||
|
||
namespace Mygento\Shipment\Setup; | ||
|
||
use Magento\Framework\Setup\UpgradeSchemaInterface; | ||
use Magento\Framework\Setup\SchemaSetupInterface; | ||
use Magento\Framework\Setup\ModuleContextInterface; | ||
|
||
class UpgradeSchema implements UpgradeSchemaInterface | ||
{ | ||
const QUOTE_SHIPPING_RATE_TABLE_NAME = 'quote_shipping_rate'; | ||
|
||
/** | ||
* @param object $installer | ||
* @param object $installer | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function upgrade( | ||
SchemaSetupInterface $setup, | ||
ModuleContextInterface $context | ||
) { | ||
$installer = $setup; | ||
|
||
$installer->startSetup(); | ||
if (version_compare($context->getVersion(), '2.2.7') < 0) { | ||
$this->updateQuoteShippingRateTable($installer); | ||
} | ||
$installer->endSetup(); | ||
} | ||
|
||
/** | ||
* Update table 'quote_shipping_rate' | ||
* | ||
* @param object $installer | ||
*/ | ||
protected function updateQuoteShippingRateTable($installer) | ||
{ | ||
$connection = $installer->getConnection(); | ||
|
||
$connection->addColumn( | ||
$installer->getTable(self::QUOTE_SHIPPING_RATE_TABLE_NAME), | ||
'estimate', | ||
[ | ||
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, | ||
'length' => 255, | ||
'nullable' => true, | ||
'comment' => 'Delivery estimate date' | ||
] | ||
); | ||
$connection->addColumn( | ||
$installer->getTable(self::QUOTE_SHIPPING_RATE_TABLE_NAME), | ||
'latitude', | ||
[ | ||
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, | ||
'length' => 255, | ||
'nullable' => true, | ||
'comment' => 'Delivery pickpoint latitude' | ||
] | ||
); | ||
$connection->addColumn( | ||
$installer->getTable(self::QUOTE_SHIPPING_RATE_TABLE_NAME), | ||
'longitude', | ||
[ | ||
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, | ||
'length' => 255, | ||
'nullable' => true, | ||
'comment' => 'Delivery pickpoint longitude' | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Quote\Model\Quote\Address\Rate"> | ||
<plugin name="mygento_shipment_get_rates" type="Mygento\Shipment\Plugin\ExtRate" /> | ||
</type> | ||
<type name="Magento\Quote\Model\Cart\ShippingMethodConverter"> | ||
<plugin name="mygento_shipment_shipping_method_converter" type="Mygento\Shipment\Plugin\ExtShippingMethodManagement" /> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<config> | ||
<extension_attributes for="Magento\Quote\Api\Data\ShippingMethodInterface"> | ||
<attribute code="estimate" type="string" /> | ||
<attribute code="latitude" type="string" /> | ||
<attribute code="longitude" type="string" /> | ||
</extension_attributes> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters