integer-net / magento2-addtocartgraphql
This module provides support to add products to cart via GraphQl
Installs: 61
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 8
Forks: 1
Open Issues: 0
Language:HTML
Type:magento2-module
Requires
- php: ~7.3||~7.4
- magento/framework: ^103.0.0
Requires (Dev)
- magento/magento-coding-standard: @dev
- pds/skeleton: ^1.0
- phpro/grumphp: ^v0.21.0
- phpstan/phpstan: ^0.12.0
- phpunit/phpunit: ^6.0|^9.0
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-11-29 06:22:50 UTC
README
This module provides support to add products to cart via GraphQl. For this to be available for guests, it is needed to force quote creation, which is done upon first checkout session creation.
Installation
-
Install it into your Magento 2 project with composer:
composer require integer-net/magento2-addtocartgraphql
-
Enable module
bin/magento setup:upgrade
For your reference, there is also an add to cart snippet included.
Usage
Configurable Products (Hyvä)
Please mind: if you plan to use this for configurable products in the Hyvä theme, you need to pass the product selection to the addtocart component.
The easiest way is to add a method to Magento_ConfigurableProduct/templates/product/view/type/options/js/configurable-options.phtml
updateCurrentSelection() {
window.dispatchEvent(
new CustomEvent(
"update-currentSelection-" + this.productId,
{
detail: this.selectedValues
}
)
);
},
This should be called whenever a selection is made, in Hyvä default you would prepend its call to the method
changeOption(optionId, value) {
[...]
this.updateCurrentSelection()
}
Default Qty (Hyvä)
The default qty on init of add to cart button is set to 1 - ideally, you would rather change Magento_Catalog/templates/product/view/quantity.phtml
to dispatch updateChangeQty
on init, as addtocart component already listens to this event - this way, you would always get the correct default qty.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Testing
Unit Tests
./vendor/bin/phpunit tests/unit
Magento Integration Tests
-
Configure test database in
dev/tests/integration/etc/install-config-mysql.php
. Read more in the Magento docs. -
Copy
tests/integration/phpunit.xml.dist
from the package todev/tests/integration/phpunit.xml
in your Magento installation. -
In that directory, run
../../../vendor/bin/phpunit
Security
If you discover any security related issues, please email security@integer-net.de instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.