-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nordcomputer/develop
Develop
- Loading branch information
Showing
13 changed files
with
156 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Nordcomputer\Stockfilter\Cron; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; | ||
use Magento\CatalogInventory\Api\StockRegistryInterface; | ||
use Magento\CatalogInventory\Api\Data\StockItemInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
|
||
class UpdateStockFilter | ||
{ | ||
protected $CollectionFactory; | ||
|
||
private $stockRegistry; | ||
|
||
public function __construct( | ||
CollectionFactory $CollectionFactory, | ||
StockRegistryInterface $stockRegistry, | ||
ScopeConfigInterface $scopeConfig | ||
) { | ||
$this->CollectionFactory = $CollectionFactory; | ||
$this->stockRegistry = $stockRegistry; | ||
$this->scopeConfig = $scopeConfig; | ||
} | ||
public function execute() | ||
{ | ||
if ($this->scopeConfig->getValue('cataloginventory/cronjobs/is_enabled')==1) { | ||
$collection = $this->CollectionFactory->create() | ||
->addAttributeToSelect('*') | ||
->load(); | ||
foreach ($collection as $product) { | ||
if ($this->getStockStatus($product->getId())==true) { | ||
if ($product->getFilterStock()=='' || $product->getFilterStock()==null) { | ||
$product->setFilterStock(1); | ||
$product->save(); | ||
} | ||
} else { | ||
if ($product->getFilterStock()==1) { | ||
$product->setFilterStock(''); | ||
$product->save(); | ||
} | ||
} | ||
|
||
} | ||
} | ||
return $this; | ||
} | ||
|
||
public function getStockStatus($productId) | ||
{ | ||
/** @var StockItemInterface $stockItem */ | ||
$stockItem = $this->stockRegistry->getStockItem($productId); | ||
$isInStock = $stockItem ? $stockItem->getIsInStock() : false; | ||
return $isInStock; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Nordcomputer\Stockfilter\Model\Config\Source; | ||
|
||
class Options extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource | ||
{ | ||
/** | ||
* Get all options | ||
* | ||
* @return array | ||
*/ | ||
public function getAllOptions() | ||
{ | ||
$this->_options = [ | ||
['label' => __('No'), 'value'=> '' ], | ||
['label' => __('Yes'), 'value'=> 1] | ||
]; | ||
return $this->_options; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
# Mage2 Module Nordcomputer Stockfilter | ||
# Magento 2 Module Nordcomputer Stockfilter | ||
|
||
``nordcomputer/module-stockfilter`` | ||
|
||
- [Main Functionalities](#markdown-header-main-functionalities) | ||
- [Installation](#markdown-header-installation) | ||
- [Configuration](#markdown-header-configuration) | ||
- [Specifications](#markdown-header-specifications) | ||
- [Attributes](#markdown-header-attributes) | ||
|
||
|
||
## Main Functionalities | ||
|
@@ -24,11 +22,7 @@ Enabels filtering by stock status | |
|
||
### Type 2: Composer | ||
|
||
- Make the module available in a composer repository for example: | ||
- private repository `repo.magento.com` | ||
- public repository `packagist.org` | ||
- public github repository as vcs | ||
- Add the composer repository to the configuration by running `composer config repositories.repo.magento.com composer https://repo.magento.com/` | ||
- Add the composer repository to the configuration by running `composer config repositories.nordcomputer/module-stockfilter git "[email protected]:nordcomputer/magento2-stockfilter.git"` | ||
- Install the module composer by running `composer require nordcomputer/module-stockfilter` | ||
- enable the module by running `php bin/magento module:enable Nordcomputer_Stockfilter` | ||
- apply database updates by running `php bin/magento setup:upgrade`\* | ||
|
@@ -37,15 +31,6 @@ Enabels filtering by stock status | |
|
||
## Configuration | ||
|
||
You can find the configuration for this extension in `Stores -> Configuration -> Catalog -> Inventory -> Stock Filter Cronjob Configuration` | ||
|
||
|
||
|
||
## Specifications | ||
|
||
|
||
|
||
|
||
## Attributes | ||
|
||
|
||
|
||
The Cronjob iterates over all simple products and sets the newly created attribute "filter-stock" according to the stock status of the product. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd"> | ||
<acl> | ||
<resources> | ||
<resource id="Magento_Backend::admin"> | ||
<resource id="Nordcomputer_Stockfilter::main" translate="title" title="Stock Filter" sortOrder="50"/> | ||
</resource> | ||
</resources> | ||
</acl> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> | ||
<system> | ||
<section id="cataloginventory" translate="label tooltip comment" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1"> | ||
<group id="cronjobs" translate="label tooltip comment" type="text" sortOrder="999999" showInDefault="1" showInWebsite="1" showInStore="1"> | ||
<resource>Nordcomputer_Stockfilter::main</resource> | ||
<label>Stock Filter Cronjob Configuration</label> | ||
<field id="is_enabled" translate="label" type="select" sortOrder="2" showInDefault="1" canRestore="1"> | ||
<label>Enable Cronjob for stock-filter</label> | ||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model> | ||
</field> | ||
<field id="cronjobupdate" translate="label tooltip comment" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> | ||
<label>Cronjob for updating stock-filter</label> | ||
<comment>Set time for cronjob (for example: * * * * * to run every minute)</comment> | ||
</field> | ||
</group> | ||
</section> | ||
|
||
</system> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"> | ||
<default> | ||
<cataloginventory> | ||
<cronjobs> | ||
<is_enabled>1</is_enabled> | ||
<cronjobupdate>/30 * * * *</cronjobupdate> | ||
</cronjobs> | ||
</cataloginventory> | ||
</default> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/cron_groups.xsd"> | ||
<group id="filterstock"> | ||
<schedule_generate_every>1</schedule_generate_every> | ||
<schedule_ahead_for>4</schedule_ahead_for> | ||
<schedule_lifetime>2</schedule_lifetime> | ||
<history_cleanup_every>10</history_cleanup_every> | ||
<history_success_lifetime>60</history_success_lifetime> | ||
<history_failure_lifetime>600</history_failure_lifetime> | ||
<use_separate_process>1</use_separate_process> | ||
</group> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"> | ||
<group id="filterstock"> | ||
<job name="updatestockfilter" instance="Nordcomputer\Stockfilter\Cron\UpdateStockFilter" method="execute"> | ||
<config_path>cataloginventory/cronjobs/cronjobupdate</config_path> | ||
</job> | ||
</group> | ||
</config> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?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="Nordcomputer_Stockfilter" setup_version="0.0.1"/> | ||
<module name="Nordcomputer_Stockfilter" setup_version="0.0.2"/> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"Nordcomputer Stock-Filter","Nordcomputer Lagerbestandsfilter" | ||
"Stockfilter","Lagerbestandsfilter" | ||
"Stock Filter Cronjob Configuration","Lagerbestandsfilter Cronjob Konfiguration" | ||
"Cronjob for updating stock-filter","Cronjob, um den Lagerbestandsfilter zu updaten" | ||
"stock","Lagerbestände" | ||
"Set time for cronjob (for example: * * * * * to run every minute)","Zeit(en) setzen, wann der Cronjob ausgeführt werden soll. Zum Beispiel * * * * * um jede Minute zu laufen" | ||
"In stock (Filternavigation)","Auf Lager (Filternavigation)" | ||
"In stock","Auf Lager" | ||
"Enable Cronjob for stock-filter","Cronjob für Lagerbestandsfilter aktivieren" |