Skip to content

Commit 1aa83da

Browse files
Merge pull request #243 from magmodules/release/1.21.1
Release/1.21.1
2 parents 937013c + 12f3cb2 commit 1aa83da

File tree

6 files changed

+50
-26
lines changed

6 files changed

+50
-26
lines changed

Service/Order/Import.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Exception;
1111
use Magento\CatalogInventory\Observer\ItemsForReindex;
1212
use Magento\Checkout\Model\Session as CheckoutSession;
13+
use Magento\Framework\Event\ManagerInterface;
1314
use Magento\Framework\Exception\LocalizedException;
1415
use Magento\Framework\Serialize\Serializer\Json;
1516
use Magento\Quote\Api\CartRepositoryInterface;
@@ -125,6 +126,11 @@ class Import
125126
*/
126127
protected $quoteRepository;
127128

129+
/**
130+
* @var ManagerInterface
131+
*/
132+
private $eventManager;
133+
128134
/**
129135
* @var LoggerRepository
130136
*/
@@ -149,6 +155,7 @@ public function __construct(
149155
Process\GetCustomIncrementId $getCustomIncrementId,
150156
ChannableOrderRepository $channableOrderRepository,
151157
CartRepositoryInterface $quoteRepository,
158+
ManagerInterface $eventManager,
152159
LoggerRepository $logger
153160
) {
154161
$this->configProvider = $configProvider;
@@ -169,6 +176,7 @@ public function __construct(
169176
$this->getCustomIncrementId = $getCustomIncrementId;
170177
$this->channableOrderRepository = $channableOrderRepository;
171178
$this->quoteRepository = $quoteRepository;
179+
$this->eventManager = $eventManager;
172180
$this->logger = $logger;
173181
}
174182

@@ -212,14 +220,16 @@ public function execute(ChannableOrderData $orderData): OrderInterface
212220
if ($customIncrementId = $this->getCustomIncrementId->execute($orderData, $store)) {
213221
$quote->setReservedOrderId($customIncrementId);
214222
}
215-
223+
216224
$this->quoteRepository->save($quote);
217225

218226
if ($lvbOrder && $this->configProvider->disableStockMovementForLvbOrders($storeId)) {
219227
$quote->setInventoryProcessed(true);
220228
$this->itemsForReindex->clear();
221229
}
222230

231+
$this->eventManager->dispatch('checkout_submit_before', ['quote' => $quote]);
232+
223233
$order = $this->quoteManagement->submit($quote);
224234
$order->setTransactionFee($quote->getTransactionFee());
225235

@@ -242,6 +252,9 @@ public function execute(ChannableOrderData $orderData): OrderInterface
242252
$this->afterOrderImport($order, $storeId, $lvbOrder);
243253
$this->setChannableOrderImportSuccess($channableOrder, $order);
244254
$this->orderRepository->save($order);
255+
256+
$this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
257+
245258
return $order;
246259
} catch (Exception $exception) {
247260
$couldNotImportMsg = self::COULD_NOT_IMPORT_ORDER;

Service/Order/Process/CreateInvoice.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magmodules\Channable\Service\Order\Process;
99

1010
use Magento\Framework\DB\Transaction;
11+
use Magento\Framework\Event\ManagerInterface;
1112
use Magento\Framework\Exception\CouldNotSaveException;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Sales\Api\Data\InvoiceInterface;
@@ -55,6 +56,11 @@ class CreateInvoice
5556
*/
5657
private $orderConfig;
5758

59+
/**
60+
* @var ManagerInterface
61+
*/
62+
private $eventManager;
63+
5864
/**
5965
* CreateInvoice constructor.
6066
*
@@ -70,14 +76,16 @@ public function __construct(
7076
InvoiceSender $invoiceSender,
7177
OrderCommentHistory $orderCommentHistory,
7278
ConfigProvider $configProvider,
73-
OrderConfig $orderConfig
79+
OrderConfig $orderConfig,
80+
ManagerInterface $eventManager
7481
) {
7582
$this->invoiceService = $invoiceService;
7683
$this->transaction = $transaction;
7784
$this->invoiceSender = $invoiceSender;
7885
$this->orderCommentHistory = $orderCommentHistory;
7986
$this->configProvider = $configProvider;
8087
$this->orderConfig = $orderConfig;
88+
$this->eventManager = $eventManager;
8189
}
8290

8391
/**
@@ -116,6 +124,7 @@ public function execute(OrderInterface $order)
116124

117125
$this->transaction->addObject($order)->save();
118126
$this->sendInvoice($invoice, $order);
127+
$this->eventManager->dispatch('sales_order_payment_pay', ['payment' => $order->getPayment(), 'invoice' => $invoice]);
119128
}
120129
}
121130

Service/Product/InventoryData.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,15 @@ public function getLinkedSimpleProductsFromBundle(array $skus): void
165165
public function load(array $skus, array $config): void
166166
{
167167
if (isset($config['inventory']['stock_id'])) {
168-
$this->getInventoryData($skus, (int)$config['inventory']['stock_id']);
169-
$this->getReservations($skus, (int)$config['inventory']['stock_id']);
170-
171168
if ($this->configProvider->isBundleStockCalculationEnabled((int)$config['store_id'])) {
172169
$this->getLinkedSimpleProductsFromBundle($skus);
170+
$skus += array_column(
171+
array_merge(...array_values($this->bundleParentSimpleRelation)), 'sku'
172+
);
173173
}
174-
174+
175+
$this->getInventoryData($skus, (int)$config['inventory']['stock_id']);
176+
$this->getReservations($skus, (int)$config['inventory']['stock_id']);
175177
if (!empty($config['inventory']['inventory_source_items'])) {
176178
$this->getInventorySourceItems($skus);
177179
}
@@ -277,4 +279,4 @@ private function getStockDataBySku(string $sku, array $config): array
277279
'source_item' => $sourceItems,
278280
];
279281
}
280-
}
282+
}

Service/Returns/GetSkuFromGtin.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,34 @@
88
namespace Magmodules\Channable\Service\Returns;
99

1010
use Magento\Catalog\Model\ProductFactory;
11+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
1112
use Magmodules\Channable\Api\Config\RepositoryInterface as ConfigProvider;
1213
use Magmodules\Channable\Api\Log\RepositoryInterface as LogRepository;
1314

1415
class GetSkuFromGtin
1516
{
16-
/**
17-
* @var string
18-
*/
1917
private $gtinAttribute;
20-
/**
21-
* @var ProductFactory
22-
*/
23-
private $productFactory;
24-
/**
25-
* @var ConfigProvider
26-
*/
27-
private $configProvider;
28-
/**
29-
* @var LogRepository
30-
*/
31-
private $logRepository;
18+
private ProductFactory $productFactory;
19+
private ConfigProvider $configProvider;
20+
private LogRepository $logRepository;
21+
private ProductCollectionFactory $productCollectionFactory;
3222

3323
/**
3424
* @param ProductFactory $productFactory
3525
* @param ConfigProvider $configProvider
3626
* @param LogRepository $logRepository
27+
* @param ProductCollectionFactory $productCollectionFactory
3728
*/
3829
public function __construct(
3930
ProductFactory $productFactory,
4031
ConfigProvider $configProvider,
41-
LogRepository $logRepository
32+
LogRepository $logRepository,
33+
ProductCollectionFactory $productCollectionFactory
4234
) {
4335
$this->productFactory = $productFactory;
4436
$this->configProvider = $configProvider;
4537
$this->logRepository = $logRepository;
38+
$this->productCollectionFactory = $productCollectionFactory;
4639
}
4740

4841
/**
@@ -63,7 +56,14 @@ public function execute(?string $gtin, int $storeId): ?string
6356
return $product->getSku();
6457
}
6558
}
66-
if ($product = $this->productFactory->create()->loadByAttribute($gtinAttribute, $gtin)) {
59+
$product = $this->productCollectionFactory->create()
60+
->setStoreId($storeId)
61+
->addAttributeToSelect(['sku', $gtinAttribute])
62+
->addAttributeToFilter($gtinAttribute, $gtin)
63+
->setPageSize(1)
64+
->getFirstItem();
65+
66+
if ($product && $product->getId()) {
6767
return $product->getSku();
6868
}
6969
} catch (\Exception $exception) {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magmodules/magento2-channable",
33
"description": "Channable integration for Magento 2",
44
"type": "magento2-module",
5-
"version": "1.21.0",
5+
"version": "1.21.1",
66
"license": "BSD-2-Clause",
77
"homepage": "https://github.com/magmodules/magento2-channable",
88
"require": {

etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<general>
1313
<enable>0</enable>
1414
<limit>250</limit>
15-
<version>v1.21.0</version>
15+
<version>v1.21.1</version>
1616
</general>
1717
<data>
1818
<name_attribute>name</name_attribute>

0 commit comments

Comments
 (0)