Skip to content

Commit

Permalink
Modified synchronization plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
sinisa86 committed Dec 12, 2017
1 parent 91ac8ac commit fa3bf14
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,16 @@ public function execute(SourceItemInterface $sourceItem)
$productIds = $this->idLocator->retrieveProductIdsBySkus([$sourceItem->getSku()]);
$productId = isset($productIds[$sourceItem->getSku()]) ? key($productIds[$sourceItem->getSku()]) : false;

if (!$productId) {
throw new NoSuchEntityException(__('Product with SKU "%1" does not exist', $sourceItem->getSku()));
if ($productId) {
$connection = $this->resourceConnection->getConnection();
$connection->delete(
$connection->getTableName('cataloginventory_stock_item'),
[
StockItemInterface::PRODUCT_ID . ' = ?' => $productId,
StockItemInterface::STOCK_ID . ' = ?' => Stock::DEFAULT_STOCK_ID,
Stock::WEBSITE_ID . ' = ?' => 0
]
);
}

$connection = $this->resourceConnection->getConnection();
$connection->delete(
$connection->getTableName('cataloginventory_stock_item'),
[
StockItemInterface::PRODUCT_ID . ' = ?' => $productId,
StockItemInterface::STOCK_ID . ' = ?' => Stock::DEFAULT_STOCK_ID,
Stock::WEBSITE_ID . ' = ?' => 0
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,16 @@ public function execute(SourceItemInterface $sourceItem)
$productIds = $this->idLocator->retrieveProductIdsBySkus([$sourceItem->getSku()]);
$productId = isset($productIds[$sourceItem->getSku()]) ? key($productIds[$sourceItem->getSku()]) : false;

if (!$productId) {
throw new NoSuchEntityException(__('Product with SKU "%1" does not exist', $sourceItem->getSku()));
if ($productId) {
$connection = $this->resourceConnection->getConnection();
$connection->delete(
$connection->getTableName('cataloginventory_stock_status'),
[
StockStatusInterface::PRODUCT_ID . ' = ?' => $productId,
StockItemInterface::STOCK_ID . ' = ?' => Stock::DEFAULT_STOCK_ID,
Stock::WEBSITE_ID . ' = ?' => 0
]
);
}

$connection = $this->resourceConnection->getConnection();
$connection->delete(
$connection->getTableName('cataloginventory_stock_status'),
[
StockStatusInterface::PRODUCT_ID . ' = ?' => $productId,
StockItemInterface::STOCK_ID . ' = ?' => Stock::DEFAULT_STOCK_ID,
Stock::WEBSITE_ID . ' = ?' => 0
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,19 @@ public function execute(SourceItemInterface $sourceItem)
$productIds = $this->productIdLocator->retrieveProductIdsBySkus([$sourceItem->getSku()]);
$productId = isset($productIds[$sourceItem->getSku()]) ? key($productIds[$sourceItem->getSku()]) : false;

if (!$productId) {
throw new NoSuchEntityException(
__('Product with SKU "%1" does not exist', $sourceItem->getSku())
if ($productId) {
$connection = $this->resourceConnection->getConnection();
$connection->update(
$connection->getTableName('cataloginventory_stock_item'),
[
StockItemInterface::QTY => $sourceItem->getQuantity(),
],
[
StockItemInterface::STOCK_ID . ' = ?' => $this->defaultStockProvider->getId(),
StockItemInterface::PRODUCT_ID . ' = ?' => $productId,
'website_id = ?' => 0
]
);
}

$connection = $this->resourceConnection->getConnection();
$connection->update(
$connection->getTableName('cataloginventory_stock_item'),
[
StockItemInterface::QTY => $sourceItem->getQuantity(),
],
[
StockItemInterface::STOCK_ID . ' = ?' => $this->defaultStockProvider->getId(),
StockItemInterface::PRODUCT_ID . ' = ?' => $productId,
'website_id = ?' => 0
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,20 @@ public function execute(SourceItemInterface $sourceItem)
$productIds = $this->productIdLocator->retrieveProductIdsBySkus([$sourceItem->getSku()]);
$productId = isset($productIds[$sourceItem->getSku()]) ? key($productIds[$sourceItem->getSku()]) : false;

if (!$productId) {
throw new NoSuchEntityException(
__('Product with SKU "%1" does not exist', $sourceItem->getSku())
if ($productId) {
$connection = $this->resourceConnection->getConnection();
$connection->update(
$connection->getTableName('cataloginventory_stock_status'),
[
StockStatusInterface::QTY => $sourceItem->getQuantity(),
StockStatusInterface::STOCK_STATUS => $sourceItem->getStatus()
],
[
StockStatusInterface::STOCK_ID . ' = ?' => $this->defaultStockProvider->getId(),
StockStatusInterface::PRODUCT_ID . ' = ?' => $productId,
'website_id = ?' => 0
]
);
}

$connection = $this->resourceConnection->getConnection();
$connection->update(
$connection->getTableName('cataloginventory_stock_status'),
[
StockStatusInterface::QTY => $sourceItem->getQuantity(),
StockStatusInterface::STOCK_STATUS => $sourceItem->getStatus()
],
[
StockStatusInterface::STOCK_ID . ' = ?' => $this->defaultStockProvider->getId(),
StockStatusInterface::PRODUCT_ID . ' = ?' => $productId,
'website_id = ?' => 0
]
);
}
}

0 comments on commit fa3bf14

Please sign in to comment.