Download the PHP package walkwizus/magento2-module-virtual-attribute-sales-rule without Composer
On this page you can find all versions of the php package walkwizus/magento2-module-virtual-attribute-sales-rule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download walkwizus/magento2-module-virtual-attribute-sales-rule
More information about walkwizus/magento2-module-virtual-attribute-sales-rule
Files in walkwizus/magento2-module-virtual-attribute-sales-rule
Package magento2-module-virtual-attribute-sales-rule
Short Description Virtual Attribute Sales Rule for Magento 2
License MIT
Homepage https://github.com/walkwizus/magento2-module-virtual-attribute-sales-rule
Informations about the package magento2-module-virtual-attribute-sales-rule
Walkwizus Virtual Attribute Sales Rule for Magento 2
Overview
The Virtual Attribute Sales Rule module for Magento 2 allows you to add virtual attributes to product and address conditions in Sales Rules. This module enhances the flexibility of your promotional rules by introducing custom, dynamic attributes that can be used in rule conditions.
Features
- Add virtual attributes to product conditions in Sales Rules
- Add virtual attributes to address conditions in Sales Rules
- Easily extendable to add new virtual attributes
- Compatible with Magento 2.4.4 and later versions
Requirements
- Magento 2.4.4 or later
- PHP 8.1 or later
Installation
Using Composer
-
In your Magento 2 root directory, run the following command:
-
Enable the module:
- Run the Magento setup upgrade:
Usage
After installation, the module will automatically add the configured virtual attributes to the list of available conditions when creating or editing a Sales Rule in the Magento admin panel.
To use a virtual attribute in a rule:
- Go to Marketing > Promotions > Cart Price Rules
- Create a new rule or edit an existing one
- In the Conditions / Actions tab, you will see the new virtual attributes available for selection
Adding Custom Virtual Attributes
To add your own virtual attributes:
- Create a new class that implements
Walkwizus\VirtualAttributeSalesRule\Api\Data\VirtualAttributeInterface
- Implement the required methods:
getLabel()
,getType()
,getValue()
, andgetOptionSource()
(if applicable)- Note: The
getOptionSource()
method is only necessary for attributes of type 'select' or 'multiselect'
- Note: The
-
Add your new attribute to the
di.xml
file:Or for address attributes:
Types returned by getType()
The following table illustrates the different types that should be returned by the getType()
method:
Type | Description |
---|---|
string | A text value |
numeric | A number (integer or float) |
date | A date value |
select | A single selection from a list of options |
boolean | A true/false value |
multiselect | Multiple selections from a list of options |
Note: For 'select' and 'multiselect' types, you must implement the getOptionSource()
method to provide the list of available options.
Examples of Custom Virtual Attributes
Here are two examples of how to create custom virtual attributes:
-
Product Virtual Attribute Example (with select type):
- Address Virtual Attribute Example (with boolean type):
In these examples, ProductCustomAttribute
creates a custom select attribute for products and implements getOptionSource()
, while AddressCustomAttribute
creates a boolean attribute for addresses and doesn't need to implement getOptionSource()
. You can customize these examples to fit your specific needs.
Support
If you encounter any issues or have questions, please open an issue on our GitHub repository.