integer-net / magento2-addtocartgraphql
此模块支持通过 GraphQl 添加产品到购物车
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-08-29 05:44:05 UTC
README
此模块支持通过 GraphQl 添加产品到购物车。为了使访客可用,需要强制创建报价,这在首次创建结账会话时完成。
安装
-
使用 composer 将其安装到您的 Magento 2 项目中
composer require integer-net/magento2-addtocartgraphql
-
启用模块
bin/magento setup:upgrade
为了您的参考,还包含了一个添加到购物车代码片段。
使用方法
可配置产品(Hyvä)
请注意:如果您计划在 Hyvä 主题中使用此功能进行可配置产品,您需要将产品选择传递给 addtocart 组件。
最简单的方法是向 Magento_ConfigurableProduct/templates/product/view/type/options/js/configurable-options.phtml 添加一个方法
updateCurrentSelection() {
window.dispatchEvent(
new CustomEvent(
"update-currentSelection-" + this.productId,
{
detail: this.selectedValues
}
)
);
},
应在每次选择时调用此方法,在 Hyvä 默认情况下,您会将其调用方法添加到该方法中
changeOption(optionId, value) {
[...]
this.updateCurrentSelection()
}
默认数量(Hyvä)
添加到购物车按钮初始化时的默认数量设置为 1 -理想情况下,您可能更愿意将 Magento_Catalog/templates/product/view/quantity.phtml
中的 updateChangeQty
分派在初始化时,因为 addtocart 组件已经监听此事件 -这样,您将始终获得正确的默认数量。
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
测试
单元测试
./vendor/bin/phpunit tests/unit
Magento 集成测试
-
在
dev/tests/integration/etc/install-config-mysql.php
中配置测试数据库。阅读更多关于 Magento 文档的内容。 -
将包中的
tests/integration/phpunit.xml.dist
复制到您的 Magento 安装中的dev/tests/integration/phpunit.xml
。 -
在目录中运行
../../../vendor/bin/phpunit
安全
如果您发现任何安全相关的问题,请通过电子邮件 security@integer-net.de 联系,而不是使用问题跟踪器。
致谢
许可证
MIT 许可证(MIT)。请参阅 许可证文件 了解更多信息。