0

I need to extend the functionality of Magento Catalog price rules.

I want to be possible to have a rule or a field to have the possibility to select the country where the rule should apply.

So basically, I select Italy, the rule should only apply on frontend to customers logged with an address located in Italy.

I assume it's linked to catalogrule_product_price table where I should probably add columns (As how the customer_group is managed) but I don't know how to properly modify the code in the indexer to have :

 1. The correct prices indexed
 2. The correct prices displayed on frontend

I'm also interested in a solution for any customer attributes :)

How can I achieve that ?

1 Answer 1

0

You need to add a row to the catalogrule table. Use the Setup Script to achieve this

namespace Vendor\Namespace\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

class InstallSchema implements InstallSchemaInterface
{

    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();
        $setup->getConnection()->addColumn(
        $setup->getTable('catalogrule'),
            'new_column',
            [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'length' => 32,
                'nullable' => false,
                'default' => '',
                'comment' => 'New Column'
            ]
        );

        $setup->endSetup();
    } 
}

If you need that to be displayed in the UI form, then add the new column in the Vendor/Namespace/view/adminhtml/ui_component/catalog_rule_form.xml XML file

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="rule_information">
        <field name="test_column">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string">Test Column</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">catalog_rule</item>
                    <item name="dataScope" xsi:type="string">test_column</item>
                    <item name="sortOrder" xsi:type="number">50</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>
 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.