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 cart price rules conditions. This extension enhances the flexibility of your promotional rules by introducing dynamic attributes that can be used in three key areas:
- Cart Attributes
- Cart Item Attributes
- Product Attributes
Create more sophisticated and targeted promotional rules without core code modifications.
Features
- Add virtual attributes to Cart Attribute conditions section
- Add virtual attributes to Cart Item Attribute conditions section
- Add virtual attributes to Product Attribute conditions section
- Support for multiple attribute types: string, numeric, date, select, boolean, and multiselect
Requirements
- Magento 2.4.4 or later
- PHP 8.1 or later
Installation
Using Composer (Recommended)
-
In your Magento 2 root directory, run the following command:
-
Enable the module:
-
Run the Magento setup upgrade:
-
Compile the code (in production mode):
- Clear the cache:
Usage
Step 1: Create Your Attribute Classes
Create new classes that implement Walkwizus\VirtualAttributeSalesRule\Api\Data\VirtualAttributeInterface
. Your classes must implement these methods:
getLabel()
: Returns the attribute's display namegetType()
: Returns the attribute's data typegetValue()
: Returns the attribute's value for a given modelgetOptionSource()
: Returns available options (only for 'select' and 'multiselect' types)
Supported Attribute Types
The following types can 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 available options.
Step 2: Add your attributes to di.xml
Create a di.xml
file in your module's etc
directory with the following structure:
Replace Your\Module\Model\VirtualAttribute\YourAttribute
with your actual attribute class paths, and attribute_code
with the code you want to use for each attribute.
Important: Make sure each attribute_code
is unique and does not conflict with any existing Magento attribute codes, as this could cause unexpected behavior or errors in your rules.
Implementation Examples
Here are examples of virtual attributes implementation for different section types:
Product Attribute Example
Cart Attribute Example
Cart Item Attribute Example
Select/Multiselect Example
Step 3: Use in Sales Rules
After installing your module and implementing your virtual attributes:
- Go to Marketing > Promotions > Cart Price Rules in the Magento admin
- Create or edit a rule
- In the "Conditions" tab, you'll see your virtual attributes available in the respective sections:
- Product attributes in the "Product attribute combination" condition
- Cart attributes in the "Cart attribute" condition
- Cart item attributes in the "Product attribute" condition (with "(Virtual Attribute)" suffix)
Support
For issues and support, please create an issue on the GitHub repository.