Skip to content

Commit

Permalink
Merge branch '1.0.6' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
pniel-cohen committed Feb 25, 2022
2 parents e68bc2a + 3abbc5b commit b474698
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
20 changes: 19 additions & 1 deletion Model/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Framework\UrlInterface;
use Magento\Framework\Exception\NoSuchEntityException;

/**
* Kimonix schema.
Expand Down Expand Up @@ -137,7 +138,16 @@ public function getProductImageUrl(Product $product, $imageDisplayAreas = ['prod
*/
public function getProductStockItem(Product $product)
{
return $product->getStockItem() ?: $this->stockItemRepository->get($product->getId());
try {
if($product->getTypeId() === ProductTypeGrouped::TYPE_CODE){
return false;
}
return $product->getStockItem() ?: $this->stockItemRepository->get($product->getId());
} catch (\NoSuchEntityException $e) {
return false;
} catch (\Exception $e) {
return false;
}
}

/**
Expand Down Expand Up @@ -197,6 +207,10 @@ public function getProductSchema(Product $product)
$schema["inventory"] = (int) $stockItem->getQty();
$schema["inventory_tracked"] = (bool) $stockItem->getManageStock();
$schema["is_in_stock"] = (bool) $stockItem->getIsInStock();
}else{
$schema["inventory"] = (int) 0;
$schema["inventory_tracked"] = (bool) 0;
$schema["is_in_stock"] = (bool) $product->isSalable();
}

$childKey = false;
Expand Down Expand Up @@ -248,6 +262,10 @@ public function getProductSchema(Product $product)
$childSchema["inventory_quantity"] = (int) $stockItem->getQty();
$childSchema["inventory_item"]["tracked"] = (bool) $stockItem->getManageStock();
$childSchema["inventory_item"]["is_in_stock"] = (bool) $stockItem->getIsInStock();
}else{
$childSchema["inventory_quantity"] = 0;
$childSchema["inventory_item"]["tracked"] = 0;
$childSchema["inventory_item"]["is_in_stock"] = (bool) $childProduct->isSalable();
}
$schema[$childKey][] = $childSchema;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"php": ">=5.6"
},
"type": "magento2-module",
"version": "1.0.5",
"version": "1.0.6",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Kimonix_Kimonix" setup_version="1.0.5">
<module name="Kimonix_Kimonix" setup_version="1.0.6">
<sequence>
<module name="Magento_Catalog" />
<module name="Magento_Sales" />
Expand Down

0 comments on commit b474698

Please sign in to comment.