-
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
Merged
ishakhsuvarov
merged 11 commits into
store-pickup
from
MSI-2030-add-ability-to-mark-orders-placed-with-store-pickup
Mar 23, 2019
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f82908b
MSI-2030-Add an ability to Mark Orders placed with Store Pickup.
95e7878
MSI-2030-Add an ability to Mark Orders placed with Store Pickup.
ec60951
MSI-2030-Add an ability to Mark Orders placed with Store Pickup.
5ada1ee
Merge remote-tracking branch 'origin/store-pickup' into MSI-2030-add-…
4b5296a
MSI-2030-Add an ability to Mark Orders placed with Store Pickup.
a9e1a88
Merge remote-tracking branch 'origin/store-pickup' into MSI-2030-add-…
3548061
MSI-2030-Add an ability to Mark Orders placed with Store Pickup.
b600990
MSI-2030-Add an ability to Mark Orders placed with Store Pickup.
c06e37c
MSI-2030-Add an ability to Mark Orders placed with Store Pickup.
27554a7
Merge branch 'store-pickup' into MSI-2030-add-ability-to-mark-orders-…
ishakhsuvarov 97556b5
magento-engcom/msi#2082: Minor coding style fixes
ishakhsuvarov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...ntoryInStorePickup/Model/ResourceModel/OrderPickupLocation/GetPickupLocationByOrderId.php
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,56 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Model\ResourceModel\OrderPickupLocation; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
|
||
/** | ||
* Get Pickup Location identifier by order identifier. | ||
*/ | ||
class GetPickupLocationByOrderId | ||
{ | ||
private const ORDER_ID = 'order_id'; | ||
|
||
private const PICKUP_LOCATION_CODE = 'pickup_location_code'; | ||
|
||
/** | ||
* @var \Magento\Framework\App\ResourceConnection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* @param \Magento\Framework\App\ResourceConnection $connection | ||
*/ | ||
public function __construct( | ||
ResourceConnection $connection | ||
) { | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* Fetch pickup location identifier by order identifier. | ||
* | ||
* @param int $orderId | ||
* | ||
* @return string|null | ||
*/ | ||
public function execute(int $orderId): ?string | ||
{ | ||
$connection = $this->connection->getConnection(); | ||
$table = $this->connection->getTableName('inventory_pickup_location_order'); | ||
|
||
$select = $connection->select() | ||
->from($table, [self::PICKUP_LOCATION_CODE => self::PICKUP_LOCATION_CODE]) | ||
->where(self::ORDER_ID . '= ?', $orderId) | ||
->limit(1); | ||
|
||
$id = $connection->fetchOne($select); | ||
|
||
return $id ?: null; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...nventoryInStorePickup/Model/ResourceModel/OrderPickupLocation/SaveOrderPickupLocation.php
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,56 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Model\ResourceModel\OrderPickupLocation; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
|
||
/** | ||
* Save Order Pickup Location | ||
*/ | ||
class SaveOrderPickupLocation | ||
{ | ||
private const ORDER_ID = 'order_id'; | ||
private const PICKUP_LOCATION_CODE = 'pickup_location_code'; | ||
|
||
/** | ||
* @var \Magento\Framework\App\ResourceConnection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* GetPickupLocationByOrderId constructor. | ||
* | ||
* @param \Magento\Framework\App\ResourceConnection $connection | ||
*/ | ||
public function __construct( | ||
ResourceConnection $connection | ||
) { | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* Fetch pickup location identifier by order identifier. | ||
* | ||
* @param int $orderId | ||
* @param string $pickupLocationCode | ||
* | ||
* @return void | ||
*/ | ||
public function execute(int $orderId, string $pickupLocationCode): void | ||
{ | ||
$connection = $this->connection->getConnection(); | ||
$table = $this->connection->getTableName('inventory_pickup_location_order'); | ||
|
||
$data = [ | ||
self::ORDER_ID => $orderId, | ||
self::PICKUP_LOCATION_CODE => $pickupLocationCode | ||
]; | ||
|
||
$connection->insertOnDuplicate($table, $data); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...ode/Magento/InventoryInStorePickup/Plugin/Sales/Order/GetPickupLocationForOrderPlugin.php
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,73 @@ | ||
<?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\OrderPickupLocation\GetPickupLocationByOrderId; | ||
use Magento\Sales\Api\Data\OrderExtensionFactory; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
|
||
/** | ||
* Set Pickup Location identifier to Order Entity. | ||
*/ | ||
class GetPickupLocationForOrderPlugin | ||
{ | ||
/** | ||
* @var OrderExtensionFactory | ||
*/ | ||
private $orderExtensionFactory; | ||
|
||
/** | ||
* @var GetPickupLocationByOrderId | ||
*/ | ||
private $getPickupLocationByOrderId; | ||
|
||
/** | ||
* @param OrderExtensionFactory $orderExtensionFactory | ||
* @param GetPickupLocationByOrderId $getPickupLocationByOrderId | ||
*/ | ||
public function __construct( | ||
OrderExtensionFactory $orderExtensionFactory, | ||
GetPickupLocationByOrderId $getPickupLocationByOrderId | ||
) { | ||
$this->orderExtensionFactory = $orderExtensionFactory; | ||
$this->getPickupLocationByOrderId = $getPickupLocationByOrderId; | ||
} | ||
|
||
/** | ||
* Add Pickup Location Code extension attribute when loading Order with OrderRepository. | ||
* | ||
* @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->getPickupLocationCode()) { | ||
return $order; | ||
} | ||
|
||
$pickupLocationCode = $this->getPickupLocationByOrderId->execute((int)$order->getEntityId()); | ||
|
||
if ($pickupLocationCode) { | ||
$extension->setPickupLocationCode($pickupLocationCode); | ||
} | ||
|
||
$order->setExtensionAttributes($extension); | ||
|
||
return $order; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...de/Magento/InventoryInStorePickup/Plugin/Sales/Order/SavePickupLocationForOrderPlugin.php
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,55 @@ | ||
<?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\OrderPickupLocation\SaveOrderPickupLocation; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
|
||
/** | ||
* Save Pickup Location identifier, related to the Order Entity. | ||
*/ | ||
class SavePickupLocationForOrderPlugin | ||
{ | ||
/** | ||
* @var SaveOrderPickupLocation | ||
*/ | ||
private $saveOrderPickupLocation; | ||
|
||
/** | ||
* @param SaveOrderPickupLocation $saveOrderPickupLocation | ||
*/ | ||
public function __construct(SaveOrderPickupLocation $saveOrderPickupLocation) | ||
{ | ||
$this->saveOrderPickupLocation = $saveOrderPickupLocation; | ||
} | ||
|
||
/** | ||
* Save Order to Pickup Location relation when saving the order. | ||
* | ||
* @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->getPickupLocationCode()) { | ||
$this->saveOrderPickupLocation->execute((int)$result->getEntityId(), $extension->getPickupLocationCode()); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
app/code/Magento/InventoryInStorePickup/Test/Integration/PickupLocationOrderTest.php
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,85 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Test\Integration; | ||
|
||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Sales\Api\Data\OrderExtensionFactory; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PickupLocationOrderTest extends TestCase | ||
{ | ||
/** @var ObjectManagerInterface */ | ||
private $objectManager; | ||
|
||
/** @var OrderRepositoryInterface */ | ||
private $orderRepository; | ||
|
||
/** @var SearchCriteriaBuilder */ | ||
private $searchCriteriaBuilder; | ||
|
||
/** @var OrderExtensionFactory */ | ||
private $orderExtensionFactory; | ||
|
||
protected function setUp() | ||
{ | ||
$this->objectManager = Bootstrap::getObjectManager(); | ||
|
||
$this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class); | ||
$this->searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class); | ||
$this->orderExtensionFactory = $this->objectManager->get(OrderExtensionFactory::class); | ||
} | ||
|
||
/** | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/create_in_store_pickup_quote_on_eu_website.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/place_order.php | ||
* | ||
* @magentoDbIsolation disabled | ||
*/ | ||
public function testPickupLocationSaveWithOrder() | ||
{ | ||
$sourceId = 'eu-1'; | ||
|
||
$searchCriteria = $this->searchCriteriaBuilder | ||
->addFilter('increment_id', 'in_store_pickup_test_order') | ||
->create(); | ||
/** @var OrderInterface $createdOrder */ | ||
$createdOrder = current($this->orderRepository->getList($searchCriteria)->getItems()); | ||
$orderId = $createdOrder->getEntityId(); | ||
|
||
$extension = $createdOrder->getExtensionAttributes(); | ||
|
||
if (empty($extension)) { | ||
/** @var \Magento\Sales\Api\Data\OrderExtensionInterface $extension */ | ||
$extension = $this->orderExtensionFactory->create(); | ||
} | ||
|
||
$extension->setPickupLocationCode($sourceId); | ||
$createdOrder->setExtensionAttributes($extension); | ||
|
||
$this->orderRepository->save($createdOrder); | ||
|
||
// Remove value to re-load from DB during 'get'. | ||
$extension->setPickupLocationCode(null); | ||
|
||
$order = $this->orderRepository->get($orderId); | ||
|
||
$this->assertEquals($order->getExtensionAttributes()->getPickupLocationCode(), $sourceId); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...Magento/InventoryInStorePickup/Test/_files/create_in_store_pickup_quote_on_eu_website.php
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,59 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Quote\Api\CartManagementInterface; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Api\Data\AddressInterface; | ||
use Magento\Quote\Api\Data\AddressInterfaceFactory; | ||
use Magento\Store\Api\StoreRepositoryInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
/** @var CartRepositoryInterface $cartRepository */ | ||
$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class); | ||
/** @var CartManagementInterface $cartManagement */ | ||
$cartManagement = Bootstrap::getObjectManager()->get(CartManagementInterface::class); | ||
/** @var AddressInterfaceFactory $addressFactory */ | ||
$addressFactory = Bootstrap::getObjectManager()->get(AddressInterfaceFactory::class); | ||
/** @var StoreRepositoryInterface $storeRepository */ | ||
$storeRepository = Bootstrap::getObjectManager()->get(StoreRepositoryInterface::class); | ||
/** @var StoreManagerInterface\ $storeManager */ | ||
$storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class); | ||
|
||
$cartId = $cartManagement->createEmptyCart(); | ||
$cart = $cartRepository->get($cartId); | ||
$cart->setCustomerEmail('admin@example.com'); | ||
$cart->setCustomerIsGuest(true); | ||
$store = $storeRepository->get('store_for_eu_website'); | ||
$cart->setStoreId($store->getId()); | ||
$storeManager->setCurrentStore($store->getCode()); | ||
|
||
/** @var AddressInterface $address */ | ||
$address = $addressFactory->create( | ||
[ | ||
'data' => [ | ||
AddressInterface::KEY_COUNTRY_ID => 'US', | ||
AddressInterface::KEY_REGION_ID => 15, | ||
AddressInterface::KEY_LASTNAME => 'Doe', | ||
AddressInterface::KEY_FIRSTNAME => 'John', | ||
AddressInterface::KEY_STREET => 'example street', | ||
AddressInterface::KEY_EMAIL => 'customer@example.com', | ||
AddressInterface::KEY_CITY => 'Los Angeles', | ||
AddressInterface::KEY_TELEPHONE => '937 99 92', | ||
AddressInterface::KEY_POSTCODE => 12345 | ||
] | ||
] | ||
); | ||
$cart->setReservedOrderId('in_store_pickup_test_order'); | ||
$cart->setBillingAddress($address); | ||
$cart->setShippingAddress($address); | ||
$cart->getPayment()->setMethod('checkmo'); | ||
/** Will be replaced with 'In Store Pickup' delivery method */ | ||
$cart->getShippingAddress()->setShippingMethod('flatrate_flatrate'); | ||
$cart->getShippingAddress()->setCollectShippingRates(true); | ||
$cart->getShippingAddress()->collectShippingRates(); | ||
$cartRepository->save($cart); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I love how you save a US address to the Quote in fixture designed for EU Website :)