-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2 — Add Extension Attribute Delivery Date
- Loading branch information
Showing
5 changed files
with
352 additions
and
1 deletion.
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
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,53 @@ | ||
<?php | ||
/** | ||
* @category Prestafy | ||
* @package Prestafy_FedexExtended | ||
* @author Andresa Martins <[email protected]> | ||
* @copyright Copyright (c) 2020 Prestafy eCommerce Solutions (https://www.prestafy.com.br) | ||
* @license https://prestafy.com.br/licenses/free-for-use PRESTAFY FREE FOR USE | ||
*/ | ||
namespace Prestafy\FedexExtended\Plugin\Carrier; | ||
|
||
use Magento\Quote\Api\Data\ShippingMethodExtensionFactory; | ||
|
||
/** | ||
* Class DeliveryDate | ||
* @package Prestafy\FedexExtended\Plugin\Carrier | ||
*/ | ||
class DeliveryDate | ||
{ | ||
/** | ||
* @var ShippingMethodExtensionFactory | ||
*/ | ||
protected $extensionFactory; | ||
|
||
/** | ||
* DeliveryDate constructor. | ||
* @param ShippingMethodExtensionFactory $extensionFactory | ||
*/ | ||
public function __construct( | ||
ShippingMethodExtensionFactory $extensionFactory | ||
) { | ||
$this->extensionFactory = $extensionFactory; | ||
} | ||
|
||
/** | ||
* Add extension attribute delivery_date to Shipping method | ||
* | ||
* @param $subject | ||
* @param \Magento\Quote\Api\Data\ShippingMethodInterface $result | ||
* @param \Magento\Quote\Model\Quote\Address\Rate $rateModel | ||
* | ||
* @return \Magento\Quote\Api\Data\ShippingMethodInterface | ||
*/ | ||
public function afterModelToDataObject($subject, $result, $rateModel) | ||
{ | ||
$extensionAttribute = $result->getExtensionAttributes() ? $result->getExtensionAttributes() : | ||
$this->extensionFactory->create(); | ||
|
||
$extensionAttribute->setDeliveryDate($rateModel->getDeliveryDate()); | ||
$result->setExtensionAttributes($extensionAttribute); | ||
|
||
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,32 @@ | ||
<?php | ||
/** | ||
* @category Prestafy | ||
* @package Prestafy_FedexExtended | ||
* @author Andresa Martins <[email protected]> | ||
* @copyright Copyright (c) 2020 Prestafy eCommerce Solutions (https://www.prestafy.com.br) | ||
* @license https://prestafy.com.br/licenses/free-for-use PRESTAFY FREE FOR USE | ||
*/ | ||
namespace Prestafy\FedexExtended\Plugin\Quote\Address; | ||
/** | ||
* Class Rate | ||
* @package Prestafy\FedexExtended\Plugin\Quote\Address | ||
*/ | ||
class Rate | ||
{ | ||
/** | ||
* Add extension attribute delivery_date to Result model | ||
* | ||
* @param \Magento\Quote\Model\Quote\Address\AbstractResult $rate | ||
* @return \Magento\Quote\Model\Quote\Address\Rate | ||
*/ | ||
public function afterImportShippingRate($subject, $result, $rate) | ||
{ | ||
if ($rate instanceof \Magento\Quote\Model\Quote\Address\RateResult\Method) { | ||
$result->setDeliveryDate( | ||
$rate->getDeliveryDate() | ||
); | ||
} | ||
|
||
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
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,18 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* @category Prestafy | ||
* @package Prestafy_FedexExtended | ||
* @author Andresa Martins <[email protected]> | ||
* @copyright Copyright (c) 2020 Prestafy eCommerce Solutions (https://www.prestafy.com.br) | ||
* @license https://prestafy.com.br/licenses/free-for-use PRESTAFY FREE FOR USE | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"> | ||
<extension_attributes for="Magento\Quote\Api\Data\ShippingMethodInterface"> | ||
<attribute code="delivery_date" type="string"/> | ||
</extension_attributes> | ||
<extension_attributes for="Magento\Checkout\Api\Data\ShippingInformationInterface"> | ||
<attribute code="delivery_date" type="string"/> | ||
</extension_attributes> | ||
</config> |