infrangible / m2-catalog-product-option
Shared groundwork for Infrangible's product option modules: an extended price calculation for custom options on the product page that other option modules build on.
Package info
github.com/infrangible-dev/m2-catalog-product-option
Type:magento2-module
pkg:composer/infrangible/m2-catalog-product-option
Requires
- php: >=8.1
- fewedev/base: ~2.4.0
- infrangible/m2-foundation: ~3.0.1
- magento/framework: ~103.0.6
- magento/module-catalog: ~104.0.0
Requires (Dev)
- infrangible/phpstan-magento: ~1.2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Shared base of the Infrangible modules for custom product options. It extends the price script of custom options on the product page and builds the price configuration of options for other lists of options, so that other modules can change both.
Price script
The module replaces Magento's price script of custom options (priceOptions) with the widget
Infrangible_CatalogProductOption/js/price-options, which extends Magento's widget:
- Options without their own handler get a default handler that calculates the price changes like Magento does for all standard option types (text field, text area, drop-down, multiple select, radio buttons, checkboxes, file).
- When a shopper changes an option, the option triggers the jQuery event
product_option_changedwith the option ID. - The default handler triggers the jQuery event
product_option_changeswith the option ID, the option hash, the option element, the price configuration of all options and the calculated price changes.
Other modules extend the widget with a RequireJS mixin of Infrangible_CatalogProductOption/js/price-options, for
example to add handlers for their own option types.
Price configuration
Infrangible\CatalogProductOption\Helper\Data builds the price configuration that the price script needs for a list
of options, like Magento's block of product options does for the options of the product page:
getOptionsJsonConfig(array $options): stringreturns it as JSON for the template.getOptionsJsonConfigData(array $options): arrayreturns it as array, by option ID and, for options with values, by value ID. Each entry contains the old price, the base price (without tax) and the final price (with tax) in the currency of the store, the price type and the title.
Before it returns the configuration, the helper dispatches the event catalog_product_option_price_configuration_after
with the configuration in configObj (a DataObject with the key config) and the options in options. Observers
can change the configuration in configObj.
Requirements
- Magento Open Source or Adobe Commerce 2.4.6 or newer
- PHP 8.1 or newer
Installation
composer require infrangible/m2-catalog-product-option bin/magento module:enable Infrangible_CatalogProductOption bin/magento setup:upgrade
In production mode, also run bin/magento setup:di:compile and bin/magento setup:static-content:deploy.
License
Infrangible Catalog Product Option is licensed under the MIT License - see the LICENSE file for details.