Skip to content

Commit

Permalink
[FEATURE][SEDG-323] Changed crons to have proper DI and removed sku p…
Browse files Browse the repository at this point in the history
…refix
  • Loading branch information
DjQuinnEXP committed Mar 23, 2023
1 parent c36361b commit 3b26e7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cron/API/OrderStatusImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ protected function getItemsToShip(
$skuPrefix = $this->helper->getSkuPrefix();

foreach ($magentoOrder->getAllItems() as $item) {
$itemSku = $skuPrefix . $item->getSku();
$itemSku = $item->getSku();

if ($item->getData("parent_item_id")) {
$this->moduleLog(' - Parent item exists, skipping shipping on this one.');
Expand Down
11 changes: 9 additions & 2 deletions Cron/API/StockMutations.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class StockMutations extends AbstractCron
*/
protected TransportBuilder $transportBuilder;

/**
* @var StockRegistryInterface
*/
protected $stockRegistry;

/**
* @param Data $helper
* @param DirectoryList $directoryList
Expand All @@ -40,8 +45,10 @@ public function __construct(
ConfigInterface $config,
TransportBuilder $transportBuilder,
StoreManager $storeManager,
StockRegistryInterface $stockRegistry,
array $settings = []
) {
$this->stockRegistry = $stockRegistry;
parent::__construct($helper, $directoryList, $monolog, $config, $transportBuilder, $storeManager, $settings);
}

Expand Down Expand Up @@ -88,14 +95,14 @@ protected function processMutations()
$sku = $stockMutation->getSku();
$qty = $stockMutation->getStock();
try {
$stockItem = $this->stockregistry->getStockItemBySku($sku);
$stockItem = $this->stockRegistry->getStockItemBySku($sku);
$this->serviceLog($stream, sprintf('Setting product stock qty of sku %s with Magento ID %s to %s', $sku,
$stockItem->getProductId(), $qty));

$oldQty = $stockItem->getQty();
$stockItem->setQty($qty);
if (round($oldQty, 0) != round($qty, 0)) {
$id = $this->stockregistry->updateStockItemBySku($sku, $stockItem);
$id = $this->stockRegistry->updateStockItemBySku($sku, $stockItem);

$this->serviceLog($stream, sprintf(
'Successfully updated stock for product %s with Magento ID %s and Magento Stock item ID %s from %s to %s',
Expand Down

0 comments on commit 3b26e7f

Please sign in to comment.