Skip to content

Commit

Permalink
Merge pull request #90 from magmodules/1.4.17
Browse files Browse the repository at this point in the history
1.4.17
  • Loading branch information
Marvin-Magmodules authored Apr 6, 2020
2 parents 2d9286f + 3aff5ed commit 4027685
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 21 deletions.
1 change: 0 additions & 1 deletion Controller/Order/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public function execute()
$request = $this->getRequest();
$storeId = $request->getParam('store');
$response = $this->orderHelper->validateRequestData($request);

try {
if (empty($response['errors'])) {
try {
Expand Down
21 changes: 20 additions & 1 deletion Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,17 @@
class Order
{

/**
* @var null
*/
public $storeId = null;
/**
* @var bool
*/
public $importCustomer = false;
/**
* @var bool
*/
public $lvb = false;

/**
Expand Down Expand Up @@ -156,6 +165,10 @@ class Order
* @var AddItems
*/
private $addItems;
/**
* @var Config
*/
private $config;

/**
* Order constructor.
Expand Down Expand Up @@ -187,6 +200,7 @@ class Order
* @param CreateInvoice $createInvoice
* @param AddressData $addressData
* @param AddItems $addItems
* @param Config $config
*/
public function __construct(
StoreManagerInterface $storeManager,
Expand Down Expand Up @@ -215,7 +229,8 @@ public function __construct(
Registry $registry,
CreateInvoice $createInvoice,
AddressData $addressData,
AddItems $addItems
AddItems $addItems,
Config $config
) {
$this->storeManager = $storeManager;
$this->product = $product;
Expand Down Expand Up @@ -244,6 +259,7 @@ public function __construct(
$this->createInvoice = $createInvoice;
$this->addressData = $addressData;
$this->addItems = $addItems;
$this->config = $config;
}

/**
Expand All @@ -260,6 +276,8 @@ public function importOrder($data, $storeId)
$this->lvb = ($data['order_status'] == 'shipped') ? true : false;

try {
$this->checkoutSession->setForceBackorder($this->config->getEnableBackorders());

$store = $this->storeManager->getStore($storeId);
$cartId = $this->cartManagementInterface->createEmptyCart();
$cart = $this->cartRepositoryInterface->get($cartId)->setStore($store)->setCurrency()->setIsSuperMode(true);
Expand Down Expand Up @@ -320,6 +338,7 @@ public function importOrder($data, $storeId)
$this->generalHelper->addTolog('importOrder: ' . $data['channable_id'], $e->getMessage());
return $this->jsonRepsonse($e->getMessage(), '', $data['channable_id']);
} finally {
$this->checkoutSession->unsForceBackorder();
$this->checkoutSession->unsChannableEnabled();
$this->checkoutSession->unsChannableShipping();
$this->checkoutSession->unsChannableSkipQtyCheck();
Expand Down
53 changes: 53 additions & 0 deletions Plugin/AfterGetBackorders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright © Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magmodules\Channable\Plugin;

use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterface;
use Magento\Checkout\Model\Session as CheckoutSession;

/**
* Class AfterGetBackorders
*
*/
class AfterGetBackorders
{

/**
* @var CheckoutSession
*/
private $checkoutSession;

/**
* AfterGetBackorders constructor.
* @param CheckoutSession $checkoutSession
*/
public function __construct(
CheckoutSession $checkoutSession
) {
$this->checkoutSession = $checkoutSession;
}

/**
* Force backorder enabling for order import
*
* @param $subject
* @param int $result
* @return int $result
*/
public function afterGetBackorders(
$subject,
$result
) {
if ($this->checkoutSession->getForceBackorder()
&& interface_exists(ProductSalableResultInterface::class)
) {
return 1;
}

return $result;
}
}
47 changes: 30 additions & 17 deletions Plugin/AroundIsSalableWithReservationsCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@

namespace Magmodules\Channable\Plugin;

use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterfaceFactory;
use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterface;
use Magento\Checkout\Model\Session as CheckoutSession;

/**
* Class AroundIsSalableWithReservationsCondition
*
* This class has also a hidden dependencies not listed in the constuctor:
* - \Magento\InventorySalesApi\Api\Data\ProductSalableResultInterface
*
* This class is only loaded when MSI is enabled, but when setup:di:compile runs it will still fail on thoses classes
* in Magento 2.2 because they don't exists. That's why they are using the object manager.
*/
class AroundIsSalableWithReservationsCondition
{

Expand All @@ -17,44 +26,48 @@ class AroundIsSalableWithReservationsCondition
*/
private $checkoutSession;

/**
* @var ProductSalableResultInterfaceFactory
*/
private $productSalableResultFactory;

/**
* AroundIsSalableWithReservationsCondition constructor.
* @param CheckoutSession $checkoutSession
* @param ProductSalableResultInterfaceFactory $productSalableResultFactory
*/
public function __construct(
CheckoutSession $checkoutSession,
ProductSalableResultInterfaceFactory $productSalableResultFactory
)
{
CheckoutSession $checkoutSession
) {
$this->checkoutSession = $checkoutSession;
$this->productSalableResultFactory = $productSalableResultFactory;
}

/**
* Skip MSI Salable With Reservations check on submitting quote for LVB Orders,
* or with "Enable order for out of stock items" enabled.
*
* LVB Orders are shipped from external warehouse and have no impact on stock movement,
* thus should also be skipped from Salable Check.
*
* @param $subject
* @param \Closure $proceed
* @param string $sku
* @param int $stockId
* @param float $requestedQty
* @return \Magento\InventorySalesApi\Api\Data\ProductSalableResultInterface
* @return mixed
*/
public function aroundExecute(
$subject,
\Closure $proceed,
$proceed,
string $sku,
int $stockId,
float $requestedQty
) {
if ($this->checkoutSession->getChannableSkipQtyCheck()) {
return $this->productSalableResultFactory->create(['errors' => []]);
if ($this->checkoutSession->getChannableSkipQtyCheck()
&& interface_exists(ProductSalableResultInterface::class)
) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

return $objectManager->getInstance()->create(
ProductSalableResultInterface::class,
['errors' => []]
);
}

$proceed($sku, $stockId, $requestedQty);
return $proceed($sku, $stockId, $requestedQty);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magmodules/magento2-channable",
"description": "Channable integration for Magento 2",
"type": "magento2-module",
"version": "1.4.16",
"version": "1.4.17",
"license": "BSD-2-Clause",
"homepage": "https://github.com/magmodules/magento2-channable",
"require": {
Expand Down
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@
<type name="Magento\InventorySales\Model\IsProductSalableForRequestedQtyCondition\IsSalableWithReservationsCondition">
<plugin name="chanable_skip_salable_check_lvb_orders" type="Magmodules\Channable\Plugin\AroundIsSalableWithReservationsCondition" />
</type>
<type name="Magento\CatalogInventory\Model\Configuration">
<plugin name="chanable_force_backorder" type="Magmodules\Channable\Plugin\AfterGetBackorders" />
</type>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magmodules_Channable" setup_version="1.4.16"/>
<module name="Magmodules_Channable" setup_version="1.4.17"/>
</config>

0 comments on commit 4027685

Please sign in to comment.