Skip to content

Latest commit

 

History

History
119 lines (80 loc) · 4.34 KB

README.md

File metadata and controls

119 lines (80 loc) · 4.34 KB

IntegerNet_AddToCartGraphQl Magento Module

Latest Version on Packagist Software License Build Status Supported Magento Versions

Coverage Status Quality Score Maintainability


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

  1. Install it into your Magento 2 project with composer:

    composer require integer-net/magento2-addtocartgraphql
    
  2. 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

  1. Configure test database in dev/tests/integration/etc/install-config-mysql.php. Read more in the Magento docs.

  2. Copy tests/integration/phpunit.xml.dist from the package to dev/tests/integration/phpunit.xml in your Magento installation.

  3. 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.