This repository has been archived by the owner on Apr 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adicionado modulo Trezo_LimitCartItemQty
- Loading branch information
1 parent
3121386
commit c533441
Showing
10 changed files
with
209 additions
and
2 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,76 @@ | ||
<?php | ||
/** | ||
* Trezo | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Magento to newer | ||
* versions in the future. If you wish to customize Magento for your | ||
* needs please refer to http://www.bseller.com.br for more information. | ||
* | ||
* @category Trezo | ||
* @package Trezo_LimitCartItemQty | ||
* | ||
* @copyright Copyright (c) 2017 Trezo. (http://www.trezo.com.br) | ||
* | ||
* @author Bruno Roeder <bruno@trezo.com.br> | ||
*/ | ||
|
||
namespace Trezo\LimitCartItemQty\Observer\Limit; | ||
|
||
class CartSave implements \Magento\Framework\Event\ObserverInterface | ||
{ | ||
protected $_checkoutSession; | ||
protected $_scopeConfig; | ||
protected $_logger; | ||
protected $_messageManager; | ||
protected $_message = null; | ||
protected $_totalQtyInCart; | ||
|
||
public function __construct( | ||
\Magento\Checkout\Model\Session $checkoutSession, | ||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, | ||
\Psr\Log\LoggerInterface $logger, | ||
\Magento\Framework\Message\ManagerInterface $messageManager | ||
) { | ||
$this->_scopeConfig = $scopeConfig; | ||
$this->_checkoutSession = $checkoutSession; | ||
$this->_logger = $logger; | ||
$this->_messageManager = $messageManager; | ||
} | ||
|
||
/** | ||
* Execute observer, limiting the qty of intens in cart | ||
* | ||
* @param \Magento\Framework\Event\Observer $observer | ||
* @return void | ||
*/ | ||
public function execute( | ||
\Magento\Framework\Event\Observer $observer | ||
) { | ||
if ($this->_scopeConfig->getValue( | ||
'limitcartitemqty/configuration/enabled', | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||
)) { | ||
$object = $observer->getObject(); | ||
// only cart item | ||
if ($object instanceof \Magento\Quote\Model\Quote\Item) { | ||
$totalQtyInCart = $object->getQuote()->getItemsQty(); | ||
$maxItemsQtyInCart = $this->_scopeConfig->getValue( | ||
'limitcartitemqty/configuration/max_item_qty', | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||
); | ||
|
||
if ($totalQtyInCart > $maxItemsQtyInCart) { | ||
$erroMessage = $this->_scopeConfig->getValue( | ||
'limitcartitemqty/configuration/error_message', | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||
); | ||
throw new \Magento\Framework\Exception\LocalizedException(__(sprintf($erroMessage, $maxItemsQtyInCart))); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,2 +1,29 @@ | ||
# module-limitcartitemqty | ||
Magento 2 modulo to limit the qty of itens in the cart. | ||
# Extensão Limitar Quantidade de Itens no Carrinho para Magento 2 (Magento CE 2) | ||
Com este módulo é possível limitar a quantidade de itens que seu cliente possui no carrinho em cada compra, possibilitando que se limite uma quantidade personalizada e que quando o limite seja atingido, uma mensagem informativa é apresentada ao seu cliente (mensagem personalizada via Admin). | ||
## Instalação | ||
### Instalar usando o [composer](https://getcomposer.org/): | ||
|
||
1. Entre na pasta raíz da sua instalação | ||
2. Digite o seguinte comando: | ||
```bash | ||
composer require mageup/module-limitcartitemqty:dev-master | ||
``` | ||
|
||
3. Digite os seguintes comandos, no terminal, para habilitar o módulo: | ||
|
||
```bash | ||
php bin/magento module:enable Trezo_LimitCartItemQty --clear-static-content | ||
php bin/magento setup:upgrade | ||
``` | ||
### ou baixar e instalar manualmente: | ||
|
||
|
||
* Criar a seguinte estrutura de pastas app/code/Trezo/LimitCartItemQty | ||
* Baixe a ultima versão [aqui](https://codeload.github.com/mageup/module-limitcartitemqty/zip/master) | ||
* Descompacte o arquivo baixado e copie as pastas para dentro do diretório criado no início | ||
* Digite os seguintes comandos, no terminal, para habilitar o módulo: | ||
|
||
```bash | ||
php bin/magento module:enable Trezo_LimitCartItemQty --clear-static-content | ||
php bin/magento setup:upgrade | ||
``` |
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,25 @@ | ||
{ | ||
"name": "trezo/module-limitcartitemqty", | ||
"description": "Limit the qty of itens in the cart.", | ||
"license": "proprietary", | ||
"authors": [ | ||
{ | ||
"name": "Trezo", | ||
"email": "contato@trezo.com.br" | ||
}, | ||
{ | ||
"name": "Bruno Roeder", | ||
"email": "bruno@trezo.com.br" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": {}, | ||
"autoload": { | ||
"psr-4": { | ||
"Trezo\\LimitCartItemQty\\": "" | ||
}, | ||
"files": [ | ||
"registration.php" | ||
] | ||
} | ||
} |
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,16 @@ | ||
<?xml version="1.0" ?> | ||
<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="Magento_Backend::stores"> | ||
<resource id="Magento_Backend::stores_settings"> | ||
<resource id="Magento_Config::config"> | ||
<resource id="Trezo_LimitCartItemQty::config_trezo_limitcartitemqty" title="limitcartitemqty"/> | ||
</resource> | ||
</resource> | ||
</resource> | ||
</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,29 @@ | ||
<?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> | ||
<tab id="trezo" sortOrder="999" translate="label"> | ||
<label>trezo</label> | ||
</tab> | ||
<section id="limitcartitemqty" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label"> | ||
<label>Limit Cart Item Qty</label> | ||
<tab>trezo</tab> | ||
<resource>Trezo_LimitCartItemQty::config_trezo_limitcartitemqty</resource> | ||
<group id="configuration" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label"> | ||
<label>Configuration</label> | ||
<field id="enabled" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label" type="select"> | ||
<label>Enabled</label> | ||
<comment/> | ||
<source_model>Magento\Config\Model\Config\Source\Enabledisable</source_model> | ||
</field> | ||
<field id="max_item_qty" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="20" translate="label" type="text"> | ||
<label>Max qty item</label> | ||
<comment/> | ||
</field> | ||
<field id="error_message" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="30" translate="label" type="text"> | ||
<label>Error message</label> | ||
<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,12 @@ | ||
<?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> | ||
<limitcartitemqty> | ||
<configuration> | ||
<enabled>0</enabled> | ||
<max_item_qty>7</max_item_qty> | ||
<error_message><![CDATA[The maximum quantity allowed in the cart is %s items per purchase.]]></error_message> | ||
</configuration> | ||
</limitcartitemqty> | ||
</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,6 @@ | ||
<?xml version="1.0" ?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> | ||
<event name="model_save_before"> | ||
<observer instance="Trezo\LimitCartItemQty\Observer\Limit\CartSave" name="trezo_limitcartitemqty_observer_model_save_before"/> | ||
</event> | ||
</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,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="Trezo_LimitCartItemQty" setup_version="1.0.0"/> | ||
</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,6 @@ | ||
"Limit Cart Item Qty","Limitar quantidade de itens no carrinho" | ||
"Enabled","Habilitado" | ||
"Max qty item","Quantidade máxima de itens" | ||
"Error message","Mensagem de erro" | ||
"The maximum quantity allowed in the cart is %s items per purchase.","A quantidade máxima permitida no carrinho é de %s itens por compra." | ||
"Configuration","Configuração" |
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,6 @@ | ||
<?php | ||
\Magento\Framework\Component\ComponentRegistrar::register( | ||
\Magento\Framework\Component\ComponentRegistrar::MODULE, | ||
'Trezo_LimitCartItemQty', | ||
__DIR__ | ||
); |