Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

261 alert functionality #321

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventorySalesAlert\Api;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;

/**
* Is product salable
*
* Used fully qualified namespaces in annotations for proper work of WebApi request parser
*
* @api
*/
interface ProductIsSalableInterface
{
/**
* @param ProductInterface $product
* @param string $websiteCode
* @param string $salesChannel
*
* @return bool
*/
public function isSalable(
ProductInterface $product,
string $websiteCode,
string $salesChannel = SalesChannelInterface::TYPE_WEBSITE
): bool;
}
63 changes: 63 additions & 0 deletions app/code/Magento/InventorySalesAlert/Model/ProductIsSalable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventorySalesAlert\Model;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\InventorySalesAlert\Api\ProductIsSalableInterface;
use Magento\InventorySales\Model\StockResolver;
use Magento\InventoryApi\Api\IsProductInStockInterface;
use Magento\Framework\App\ObjectManager;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
use Magento\Inventory\Model\IsProductInStock;

class ProductIsSalable implements ProductIsSalableInterface
{

/**
* @var \Magento\InventoryApi\Api\IsProductInStockInterface
*/
private $stockItem;

/**
* @var \Magento\InventorySales\Model\StockResolver
*/
private $stockResolver;

/**
* ProductIsSalable constructor.
*
* @param \Magento\InventorySales\Model\StockResolver $stockResolver
* @param \Magento\InventoryApi\Api\IsProductInStockInterface $stockItem
*/
public function __construct(
StockResolver $stockResolver = null,
IsProductInStockInterface $stockItem = null
) {
$this->stockItem = $stockItem ?: ObjectManager::getInstance()->get(IsProductInStock::class);
$this->stockResolver = $stockResolver ?: ObjectManager::getInstance()->get(StockResolver::class);
}


/**
* @param ProductInterface $product
*
* @return bool
*/
public function isSalable(
ProductInterface $product,
string $websiteCode,
string $salesChannel = SalesChannelInterface::TYPE_WEBSITE
): bool
{
$stock = $this->stockResolver->get($salesChannel, $websiteCode);
if ($stock->getId()) {
return $this->stockItem->execute($product->getSku(), (int) $stock->getStockId());
}
return false;
}
}
42 changes: 42 additions & 0 deletions app/code/Magento/InventorySalesAlert/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "magento/module-inventory-sales-alert",
"description": "",
"require": {
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0",
"magento/framework": "100.3.*",
"magento/module-backend": "100.0.*",
"magento/module-catalog": "100.0.*",
"magento/module-catalog-inventory": "100.0.*",
"magento/module-inventory": "100.0.*",
"magento/module-inventory-api": "100.0.*",
"magento/module-inventory-catalog": "100.0.*",
"magento/module-inventory-sales-api": "100.0.*",
"magento/module-store": "100.3.*",
"magento/module-ui": "100.3.*",
"magento/magento-composer-installer": "*"
},
"suggest": {

},
"type": "magento2-module",
"version": "0.1.0",
"license": [

],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magento\\InventorySalesAlert\\": ""
}
},
"extra": {
"map": [
[
"*",
"Magento/InventorySalesAlert"
]
]
}
}
10 changes: 10 additions & 0 deletions app/code/Magento/InventorySalesAlert/etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\InventorySalesAlert\Api\ProductIsSalableInterface" type="Magento\InventorySalesAlert\Model\ProductIsSalable"/>
</config>
6 changes: 6 additions & 0 deletions app/code/Magento/InventorySalesAlert/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_InventorySalesAlert" setup_version="0.1.0">
</module>
</config>
7 changes: 7 additions & 0 deletions app/code/Magento/InventorySalesAlert/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magento_InventorySalesAlert',
__DIR__
);
Loading