Skip to content
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

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* Get Pickup Point identifier by order identifier.
*/
class GetPickupPointByOrderId
{
const ORDER_ID = 'order_id';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these constants be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should pickup point id be a string? Maybe it's a point code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}
}
18 changes: 18 additions & 0 deletions app/code/Magento/InventoryInStorePickup/etc/db_schema.xml
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">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to discuss Pickup Point naming. It's best to align it with business domain

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
}
}
13 changes: 13 additions & 0 deletions app/code/Magento/InventoryInStorePickup/etc/di.xml
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>
7 changes: 6 additions & 1 deletion app/code/Magento/InventoryInStorePickup/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be Magento_Inventory or InventoryApi?

Also sales should be added to composer dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, dependency on Magento_Sales only.
Added to composer.json.

</sequence>
</module>
</config>