-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Msi 2030 add ability to mark orders placed with store pickup #2082
Changes from 3 commits
f82908b
95e7878
ec60951
5ada1ee
4b5296a
a9e1a88
3548061
b600990
c06e37c
27554a7
97556b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Model\ResourceModel\OrderPickupPoint; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
|
||
/** | ||
* Class GetPickupPointByOrderId. | ||
* Get Pickup Point identifier by order identifier. | ||
*/ | ||
class GetPickupPointByOrderId | ||
{ | ||
const ORDER_ID = 'order_id'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these constants be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
const PICKUP_POINT_ID = 'pickup_point_id'; | ||
|
||
/** | ||
* @var \Magento\Framework\App\ResourceConnection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* GetPickupPointByOrderId constructor. | ||
* | ||
* @param \Magento\Framework\App\ResourceConnection $connection | ||
*/ | ||
public function __construct( | ||
ResourceConnection $connection | ||
) { | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* Fetch pickup point identifier by order identifier. | ||
* | ||
* @param int $orderId | ||
* | ||
* @return string|null | ||
*/ | ||
public function execute(int $orderId):?string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should pickup point id be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
{ | ||
$connection = $this->connection->getConnection(); | ||
$table = $this->connection->getTableName('inventory_pickup_point_order'); | ||
|
||
$select = $connection->select() | ||
->from($table, [ | ||
self::PICKUP_POINT_ID => self::PICKUP_POINT_ID | ||
]) | ||
->where(self::ORDER_ID . '= ?', $orderId) | ||
->limit(1); | ||
|
||
$id = $connection->fetchOne($select); | ||
|
||
return $id ?: null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Model\ResourceModel\OrderPickupPoint; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
|
||
/** | ||
* Class SaveOrderPickupPoint. | ||
* Save Order Pickup Point | ||
*/ | ||
class SaveOrderPickupPoint | ||
{ | ||
const ORDER_ID = 'order_id'; | ||
const PICKUP_POINT_ID = 'pickup_point_id'; | ||
|
||
/** | ||
* @var \Magento\Framework\App\ResourceConnection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* GetPickupPointByOrderId constructor. | ||
* | ||
* @param \Magento\Framework\App\ResourceConnection $connection | ||
*/ | ||
public function __construct( | ||
ResourceConnection $connection | ||
) { | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* Fetch pickup point identifier by order identifier. | ||
* | ||
* @param int $orderId | ||
* @param string $pickupPointId | ||
* | ||
* @return void | ||
*/ | ||
public function execute(int $orderId, string $pickupPointId):void | ||
{ | ||
$connection = $this->connection->getConnection(); | ||
$table = $this->connection->getTableName('inventory_pickup_point_order'); | ||
|
||
$data = [ | ||
self::ORDER_ID => $orderId, | ||
self::PICKUP_POINT_ID => $pickupPointId | ||
]; | ||
|
||
$connection->insertOnDuplicate($table, $data); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Plugin\Sales\Order; | ||
|
||
use Magento\InventoryInStorePickup\Model\ResourceModel\OrderPickupPoint\GetPickupPointByOrderId; | ||
use Magento\Sales\Api\Data\OrderExtensionFactory; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
|
||
/** | ||
* Class GetPickupPointForOrderPlugin. | ||
* Set Pickup Point Identifier to Order Entity. | ||
*/ | ||
class GetPickupPointForOrderPlugin | ||
{ | ||
/** | ||
* @var OrderExtensionFactory | ||
*/ | ||
private $orderExtensionFactory; | ||
|
||
/** | ||
* @var GetPickupPointByOrderId | ||
*/ | ||
private $getPickupPointByOrderId; | ||
|
||
/** | ||
* GetPickupPointForOrderPlugin constructor. | ||
* | ||
* @param OrderExtensionFactory $orderExtensionFactory | ||
* @param GetPickupPointByOrderId $getPickupPointByOrderId | ||
*/ | ||
public function __construct( | ||
OrderExtensionFactory $orderExtensionFactory, | ||
GetPickupPointByOrderId $getPickupPointByOrderId | ||
) { | ||
$this->orderExtensionFactory = $orderExtensionFactory; | ||
$this->getPickupPointByOrderId = $getPickupPointByOrderId; | ||
} | ||
|
||
/** | ||
* @param OrderRepositoryInterface $orderRepository | ||
* @param OrderInterface $order | ||
* | ||
* @return OrderInterface | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterGet( | ||
OrderRepositoryInterface $orderRepository, | ||
OrderInterface $order | ||
):OrderInterface { | ||
$extension = $order->getExtensionAttributes(); | ||
|
||
if (empty($extension)) { | ||
$extension = $this->orderExtensionFactory->create(); | ||
} | ||
|
||
if ($extension->getPickupPointId()) { | ||
return $order; | ||
} | ||
|
||
$pickupPointId = $this->getPickupPointByOrderId->execute((int)$order->getEntityId()); | ||
|
||
if ($pickupPointId) { | ||
$extension->setPickupPointId($pickupPointId); | ||
} | ||
|
||
$order->setExtensionAttributes($extension); | ||
|
||
return $order; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Plugin\Sales\Order; | ||
|
||
use Magento\InventoryInStorePickup\Model\ResourceModel\OrderPickupPoint\SaveOrderPickupPoint; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
|
||
class SavePickupPointForOrderPlugin | ||
{ | ||
/** | ||
* @var SaveOrderPickupPoint | ||
*/ | ||
private $saveOrderPickupPoint; | ||
|
||
/** | ||
* SavePickupPointForOrderPlugin constructor. | ||
* | ||
* @param SaveOrderPickupPoint $saveOrderPickupPoint | ||
*/ | ||
public function __construct(SaveOrderPickupPoint $saveOrderPickupPoint) | ||
{ | ||
$this->saveOrderPickupPoint = $saveOrderPickupPoint; | ||
} | ||
|
||
/** | ||
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository | ||
* @param \Magento\Sales\Api\Data\OrderInterface $result | ||
* @param \Magento\Sales\Api\Data\OrderInterface $entity | ||
* | ||
* @return \Magento\Sales\Api\Data\OrderInterface | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterSave( | ||
OrderRepositoryInterface $orderRepository, | ||
OrderInterface $result, | ||
OrderInterface $entity | ||
) { | ||
$extension = $result->getExtensionAttributes(); | ||
|
||
if (!empty($extension) && $extension->getPickupPointId()) { | ||
$this->saveOrderPickupPoint->execute((int)$result->getEntityId(), $extension->getPickupPointId()); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd"> | ||
<table name="inventory_pickup_point_order" resource="default" engine="innodb"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to discuss There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to 'Pickup Location'. |
||
<column xsi:type="int" name="order_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Order ID" /> | ||
<column xsi:type="varchar" name="pickup_point_id" nullable="false" comment="Pickup Point ID"/> | ||
<constraint xsi:type="foreign" referenceId="INV_ISP_ORDER_ORDER_ID_SALES_ORDER_ENTITY_ID" table="inventory_pickup_point_order" column="order_id" referenceTable="sales_order" referenceColumn="entity_id" onDelete="CASCADE"/> | ||
<constraint xsi:type="primary" referenceId="PRIMARY"> | ||
<column name="order_id"/> | ||
</constraint> | ||
</table> | ||
</schema> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"inventory_pickup_point_order": { | ||
"column": { | ||
"order_id": true, | ||
"pickup_point_id": true | ||
}, | ||
"constraint": { | ||
"PRIMARY": true, | ||
"INV_ISP_ORDER_ORDER_ID_SALES_ORDER_ENTITY_ID": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Sales\Api\OrderRepositoryInterface"> | ||
<plugin name="get_pickup_point_for_order" type="Magento\InventoryInStorePickup\Plugin\Sales\Order\GetPickupPointForOrderPlugin"/> | ||
<plugin name="save_pickup_point_for_order" type="Magento\InventoryInStorePickup\Plugin\Sales\Order\SavePickupPointForOrderPlugin"/> | ||
</type> | ||
</config> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"> | ||
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface"> | ||
<attribute code="pickup_point_id" type="string" /> | ||
</extension_attributes> | ||
</config> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,10 @@ | |
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Magento_InventoryInStorePickup" setup_version="1.0.0" /> | ||
<module name="Magento_InventoryInStorePickup" setup_version="1.0.0"> | ||
<sequence> | ||
<module name="Magento_Sales" /> | ||
<module name="Magento_Inventory" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be Also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, dependency on Magento_Sales only. |
||
</sequence> | ||
</module> | ||
</config> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeating class name in the comment is redundant. Clear responsibility description is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.