Skip to content

Commit

Permalink
Merge pull request #3 from juashyam/marketing-grids-coverage
Browse files Browse the repository at this point in the history
Marketing grids coverage
  • Loading branch information
juashyam authored Jun 30, 2021
2 parents bfee434 + 9dcbd4d commit 893123c
Show file tree
Hide file tree
Showing 17 changed files with 569 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Block/Adminhtml/Marketing/CartRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);

namespace Juashyam\EasyAdminGrids\Block\Adminhtml\Marketing;

use Juashyam\EasyAdminGrids\Model\System\Configuration;
use Magento\Backend\Block\Widget\Button;

/**
* Extend the grid container block of cart rules to display conditionally
*/
class CartRule extends \Magento\SalesRule\Block\Adminhtml\Promo\Quote
{
/**
* @return string
*/
public function getGridHtml()
{
if ($this->_scopeConfig->isSetFlag(Configuration::XML_PATH_IS_ENABLED)
&& $this->_scopeConfig->isSetFlag(Configuration::XML_PATH_REPLACE_MARKETING_CART_RULE_LISTING)
) {
return '';
}

return parent::getGridHtml();
}

/**
* Check whether button rendering is allowed in current context
*
* @param \Magento\Backend\Block\Widget\Button\Item $item
* @return bool
*/
public function canRender(Button\Item $item)
{
if ($this->_scopeConfig->isSetFlag(Configuration::XML_PATH_IS_ENABLED)
&& $this->_scopeConfig->isSetFlag(Configuration::XML_PATH_REPLACE_MARKETING_CART_RULE_LISTING)
) {
return false;
}

return parent::canRender($item);
}
}
44 changes: 44 additions & 0 deletions Block/Adminhtml/Marketing/CatalogRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);

namespace Juashyam\EasyAdminGrids\Block\Adminhtml\Marketing;

use Juashyam\EasyAdminGrids\Model\System\Configuration;
use Magento\Backend\Block\Widget\Button;

/**
* Extend the grid container block of catalog rules to display conditionally
*/
class CatalogRule extends \Magento\CatalogRule\Block\Adminhtml\Promo\Catalog
{
/**
* @return string
*/
public function getGridHtml()
{
if ($this->_scopeConfig->isSetFlag(Configuration::XML_PATH_IS_ENABLED)
&& $this->_scopeConfig->isSetFlag(Configuration::XML_PATH_REPLACE_MARKETING_CATALOG_RULE_LISTING)
) {
return '';
}

return parent::getGridHtml();
}

/**
* Check whether button rendering is allowed in current context
*
* @param \Magento\Backend\Block\Widget\Button\Item $item
* @return bool
*/
public function canRender(Button\Item $item)
{
if ($this->_scopeConfig->isSetFlag(Configuration::XML_PATH_IS_ENABLED)
&& $this->_scopeConfig->isSetFlag(Configuration::XML_PATH_REPLACE_MARKETING_CATALOG_RULE_LISTING)
) {
return false;
}

return parent::canRender($item);
}
}
41 changes: 41 additions & 0 deletions Block/Adminhtml/Marketing/Giftcardaccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);

namespace Juashyam\EasyAdminGrids\Block\Adminhtml\Marketing;

use Juashyam\EasyAdminGrids\Model\System\Configuration;
use Magento\Backend\Block\Widget\Button;

class Giftcardaccount extends \Magento\GiftCardAccount\Block\Adminhtml\Giftcardaccount
{
/**
* @return string
*/
public function getGridHtml()
{
if ($this->_scopeConfig->isSetFlag(Configuration::XML_PATH_IS_ENABLED)
&& $this->_scopeConfig->isSetFlag(Configuration::XML_PATH_REPLACE_MARKETING_GIFT_ACC_RULE_LISTING)
) {
return '';
}

return parent::getGridHtml();
}

/**
* Check whether button rendering is allowed in current context
*
* @param \Magento\Backend\Block\Widget\Button\Item $item
* @return bool
*/
public function canRender(Button\Item $item)
{
if ($this->_scopeConfig->isSetFlag(Configuration::XML_PATH_IS_ENABLED)
&& $this->_scopeConfig->isSetFlag(Configuration::XML_PATH_REPLACE_MARKETING_GIFT_ACC_RULE_LISTING)
) {
return false;
}

return parent::canRender($item);
}
}
44 changes: 44 additions & 0 deletions Block/Adminhtml/Marketing/Targetrule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);

namespace Juashyam\EasyAdminGrids\Block\Adminhtml\Marketing;

use Juashyam\EasyAdminGrids\Model\System\Configuration;
use Magento\Backend\Block\Widget\Button;

/**
* Extend the grid container block of related product rules to display conditionally
*/
class Targetrule extends \Magento\TargetRule\Block\Adminhtml\Targetrule
{
/**
* @return string
*/
public function getGridHtml()
{
if ($this->_scopeConfig->isSetFlag(Configuration::XML_PATH_IS_ENABLED)
&& $this->_scopeConfig->isSetFlag(Configuration::XML_PATH_REPLACE_MARKETING_RELATED_RULE_LISTING)
) {
return '';
}

return parent::getGridHtml();
}

/**
* Check whether button rendering is allowed in current context
*
* @param \Magento\Backend\Block\Widget\Button\Item $item
* @return bool
*/
public function canRender(Button\Item $item)
{
if ($this->_scopeConfig->isSetFlag(Configuration::XML_PATH_IS_ENABLED)
&& $this->_scopeConfig->isSetFlag(Configuration::XML_PATH_REPLACE_MARKETING_RELATED_RULE_LISTING)
) {
return false;
}

return parent::canRender($item);
}
}
35 changes: 35 additions & 0 deletions Model/Config/Source/GiftCardAccountStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

namespace Juashyam\EasyAdminGrids\Model\Config\Source;

use Magento\Framework\Data\OptionSourceInterface;
use Magento\GiftCardAccount\Model\Giftcardaccount;

/**
* Gift Card Account Status options
*/
class GiftCardAccountStatus implements OptionSourceInterface
{
/**
* @var array
*/
private $options;

/**
* @inheritdoc
*/
public function toOptionArray()
{
if (!$this->options) {
$this->options = [
['value' => Giftcardaccount::STATE_AVAILABLE, 'label' => __('Available')],
['value' => Giftcardaccount::STATE_USED, 'label' => __('Used')],
['value' => Giftcardaccount::STATE_REDEEMED, 'label' => __('Redeemed')],
['value' => Giftcardaccount::STATE_EXPIRED, 'label' => __('Expired')]
];
}

return $this->options;
}
}
34 changes: 34 additions & 0 deletions Model/Config/Source/TargetRuleApplies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);

namespace Juashyam\EasyAdminGrids\Model\Config\Source;

use Magento\Framework\Data\OptionSourceInterface;
use Magento\TargetRule\Model\Rule;

/**
* Target Rule applies to options
*/
class TargetRuleApplies implements OptionSourceInterface
{
/**
* @var array
*/
private $options;

/**
* @inheritdoc
*/
public function toOptionArray()
{
if (!$this->options) {
$this->options = [
['value' => Rule::RELATED_PRODUCTS, 'label' => __('Related Products')],
['value' => Rule::UP_SELLS, 'label' => __('Up-sells')],
['value' => Rule::CROSS_SELLS, 'label' => __('Cross-sells')]
];
}

return $this->options;
}
}
48 changes: 48 additions & 0 deletions Model/System/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class Configuration
const XML_PATH_REPLACE_CUSTOMER_NOW_ONLINE_LISTING = "easy_admin_grids/customer/replace_now_online";
const XML_PATH_REPLACE_CUSTOMER_GROUP_LISTING = "easy_admin_grids/customer/replace_group";
const XML_PATH_REPLACE_CUSTOMER_SEGMENT_LISTING = "easy_admin_grids/customer/replace_segment";
const XML_PATH_REPLACE_MARKETING_CATALOG_RULE_LISTING = "easy_admin_grids/marketing/replace_catalog_rule";
const XML_PATH_REPLACE_MARKETING_RELATED_RULE_LISTING = "easy_admin_grids/marketing/replace_related_product_rule";
const XML_PATH_REPLACE_MARKETING_CART_RULE_LISTING = "easy_admin_grids/marketing/replace_cart_rule";
const XML_PATH_REPLACE_MARKETING_GIFT_ACC_RULE_LISTING = "easy_admin_grids/marketing/replace_giftacc_rule";
/**#@-*/

/**
Expand Down Expand Up @@ -109,4 +113,48 @@ public function canReplaceCustomerSegmentListing()
ScopeInterface::SCOPE_STORE
);
}

/**
* @return mixed
*/
public function canReplaceMarketingCatalogRuleListing()
{
return $this->scopeConfig->getValue(
self::XML_PATH_REPLACE_MARKETING_CATALOG_RULE_LISTING,
ScopeInterface::SCOPE_STORE
);
}

/**
* @return mixed
*/
public function canReplaceMarketingRelatedRuleListing()
{
return $this->scopeConfig->getValue(
self::XML_PATH_REPLACE_MARKETING_RELATED_RULE_LISTING,
ScopeInterface::SCOPE_STORE
);
}

/**
* @return mixed
*/
public function canReplaceMarketingCartRuleListing()
{
return $this->scopeConfig->getValue(
self::XML_PATH_REPLACE_MARKETING_CART_RULE_LISTING,
ScopeInterface::SCOPE_STORE
);
}

/**
* @return mixed
*/
public function canReplaceMarketingGiftAccountListing()
{
return $this->scopeConfig->getValue(
self::XML_PATH_REPLACE_MARKETING_GIFT_ACC_RULE_LISTING,
ScopeInterface::SCOPE_STORE
);
}
}
1 change: 1 addition & 0 deletions etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<argument name="gridTemplate" xsi:type="string">Hyva_Admin::grid.phtml</argument>
</arguments>
</type>
<preference for="Magento\SalesRule\Block\Adminhtml\Promo\Quote" type="Juashyam\EasyAdminGrids\Block\Adminhtml\Marketing\CartRule"/>
</config>

23 changes: 23 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<group id="marketing" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Marketing</label>
<field id="replace_catalog_rule" translate="label" type="select" sortOrder="1" showInDefault="1" showInStore="0" showInWebsite="0">
<label>Replace Catalog Price Rule Grid</label>
<comment><![CDATA[Replace the native Catalog Price Rule Grid with the Easy Admin Grid.]]></comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="replace_related_product_rule" translate="label" type="select" sortOrder="2" showInDefault="1" showInStore="0" showInWebsite="0">
<label>Replace Related Products Rules Grid</label>
<comment><![CDATA[Replace the native Related Products Rules Grid with the Easy Admin Grid.]]></comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="replace_cart_rule" translate="label" type="select" sortOrder="3" showInDefault="1" showInStore="0" showInWebsite="0">
<label>Replace Cart Price Rules Grid</label>
<comment><![CDATA[Replace the native Cart Price Rules Grid with the Easy Admin Grid.]]></comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="replace_giftacc_rule" translate="label" type="select" sortOrder="4" showInDefault="1" showInStore="0" showInWebsite="0">
<label>Replace Gift Card Accounts Grid</label>
<comment><![CDATA[Replace the native Gift Card Accounts Grid with the Easy Admin Grid.]]></comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
46 changes: 46 additions & 0 deletions view/adminhtml/hyva-grid/marketing-cart-rules-grid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<grid xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Hyva_Admin:etc/hyva-grid.xsd">
<source>
<repositoryListMethod>\Magento\SalesRule\Api\RuleRepositoryInterface::getList</repositoryListMethod>
</source>
<columns>
<include>
<column name="rule_id" label="ID"/>
<column name="name" label="Rule"/>
<column name="sort_order" label="Priority"/>
<column name="is_active" label="Status">
<option value="1" label="Active"/>
<option value="0" label="Inactive"/>
</column>
<column name="website_ids" label="Web Site" type="website_id" source="\Magento\Store\Model\ResourceModel\Website\Collection"/>
</include>
</columns>
<actions idColumn="rule_id">
<action id="edit" label="Edit" url="sales_rule/promo_quote/edit/" idParam="id"/>
</actions>
<entityConfig>
<label>
<singular>Cart Price Rule</singular>
<plural>Cart Price Rules</plural>
</label>
</entityConfig>
<navigation>
<buttons>
<button id="new" label="Add New Rule" url="sales_rule/promo_quote/new/"/>
</buttons>
<pager>
<defaultPageSize>20</defaultPageSize>
<pageSizes>20,30,50,100,200</pageSizes>
</pager>
<sorting>
<defaultSortByColumn>sort_order</defaultSortByColumn>
<defaultSortDirection>asc</defaultSortDirection>
</sorting>
<filters>
<filter column="rule_id"/>
<filter column="name"/>
<filter column="sort_order"/>
<filter column="is_active"/>
</filters>
</navigation>
</grid>
Loading

0 comments on commit 893123c

Please sign in to comment.