Skip to content

Commit

Permalink
[Magento 2.3/2.4 - Popup] #26 - Add a configuration to open automatic…
Browse files Browse the repository at this point in the history
…ally gift sales rule popup
  • Loading branch information
PierreLeMaguer authored and maximequeneau committed Jan 4, 2021
1 parent fe60139 commit 1a9a03a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Config extends AbstractHelper
* Config paths.
*/
const KEY_CONFIG_AUTOMATIC_ADD = 'smile_gift_sales_rule/configuration/automatic_add';
const KEY_CONFIG_AUTOMATIC_POPUP_OPEN = 'smile_gift_sales_rule/configuration/automatic_popup_open';
/**#@-*/

/**
Expand All @@ -40,4 +41,14 @@ public function isAutomaticAddEnabled()

return ($value == 1);
}

/**
* Get the config value for automatic_popup_open.
*
* @return bool
*/
public function isAutomaticPopupOpenEnabled(): bool
{
return (bool) $this->scopeConfig->getValue(self::KEY_CONFIG_AUTOMATIC_POPUP_OPEN);
}
}
49 changes: 49 additions & 0 deletions ViewModel/GiftRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\GiftSalesRule
* @author Pierre Le Maguer <[email protected]>
* @copyright 2020 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\GiftSalesRule\ViewModel;

use Magento\Framework\View\Element\Block\ArgumentInterface;
use Smile\GiftSalesRule\Helper\Config as GiftRuleConfig;

/**
* View Model: Gift Rule
*
* @author Pierre Le Maguer <[email protected]>
* @copyright 2020 Smile
*/
class GiftRule implements ArgumentInterface
{
/**
* @var GiftRuleConfig
*/
protected $giftRuleConfig;

/**
* @param GiftRuleConfig $giftRuleConfig Gift rule config
*/
public function __construct(GiftRuleConfig $giftRuleConfig)
{
$this->giftRuleConfig = $giftRuleConfig;
}

/**
* Is popup automatic open enabled ?
*
* @return bool
*/
public function isAutomaticPopupOpenEnabled(): bool
{
return $this->giftRuleConfig->isAutomaticPopupOpenEnabled();
}
}
5 changes: 5 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<comment>Added if there are only 1 gift product parameterized</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="automatic_popup_open" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Automatically open popup</label>
<comment>If yes, the gift selection popup is opened automatically if there is at least one product to offer.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<smile_gift_sales_rule>
<configuration>
<automatic_add>1</automatic_add>
<automatic_popup_open>0</automatic_popup_open>
</configuration>
</smile_gift_sales_rule>
</default>
Expand Down
2 changes: 2 additions & 0 deletions i18n/en_US.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"Added if there are only 1 gift product parameterized","Added if there are only 1 gift product parameterized"
"Automatically add gift product","Automatically add gift product"
"Automatically open popup","Automatically open popup"
"Edit my choices","Edit my choices"
"If yes, the gift selection popup is opened automatically if there is at least one product to offer.","If yes, the gift selection popup is opened automatically if there is at least one product to offer."
"Maximum number of products offered","Maximum number of products offered"
"Price range","Price range"
"Select gift product:","Select gift product:"
Expand Down
2 changes: 2 additions & 0 deletions i18n/fr_FR.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"Added if there are only 1 gift product parameterized","Ajouté s'il n'y a qu'un seul produit cadeau paramétré"
"Automatically add gift product","Ajouter automatiquement un produit cadeau"
"Automatically open popup","Ouvrir automatiquement la popup"
"Edit my choices","Modifier mes choix"
"If yes, the gift selection popup is opened automatically if there is at least one product to offer.","Si la configuration est activée, la popup de sélection de produits offerts est ouverte automatiquement s'il y a au moins un produit à offrir."
"Maximum number of products offered","Nombre maximum de produit offert"
"Price range","Tranche de prix"
"Select gift product:","Sélecteur des produits offerts:"
Expand Down
3 changes: 3 additions & 0 deletions view/frontend/layout/checkout_cart_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<block class="Smile\GiftSalesRule\Block\Cart\GiftRules\Rule"
name="checkout.cart.gift-rules.rule"
template="Smile_GiftSalesRule::cart/gift-rules/rule.phtml">
<arguments>
<argument name="giftRuleViewModel" xsi:type="object">Smile\GiftSalesRule\ViewModel\GiftRule</argument>
</arguments>
<block class="Smile\GiftSalesRule\Block\Cart\GiftRules\ProductItem"
name="checkout.cart.gift-rules.product-item"
template="Smile_GiftSalesRule::cart/gift-rules/product-item.phtml">
Expand Down
5 changes: 5 additions & 0 deletions view/frontend/templates/cart/gift-rules/rule.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/

/** @var $block \Smile\GiftSalesRule\Block\Cart\GiftRules\Rule */
/** @var $giftRuleViewModel \Smile\GiftSalesRule\ViewModel\GiftRule */
$giftRuleViewModel = $block->getData('giftRuleViewModel');
$rule = $block->getGiftRule();
?>

Expand All @@ -24,6 +26,9 @@ $rule = $block->getGiftRule();
<div class="popin-block" id="rule-freegift-popin-<?= $rule->getCode() ?>" data-mage-init='{
"Magento_Ui/js/modal/modal": {
"type": "popup",
<?php if ($giftRuleViewModel->isAutomaticPopupOpenEnabled()): ?>
"autoOpen": <?= $rule->getRestNumber() ? 'true' : 'false'; ?>,
<?php endif; ?>
"responsive": true,
"modalClass": "free-gift-modal",
"innerScroll": true,
Expand Down

0 comments on commit 1a9a03a

Please sign in to comment.