id_product_attribute 在 URL 中可用 - 值“10”:http://localhost/presta/women/2-10-brown-(...).html#/2-size-m
我需要从当前产品页面获取当前 id_product_attribute。可能来自 $_GET,或来自 DOM 元素,或 presta shop 变量 - 但我必须在添加到购物车之前将其传递给 JavaScript 函数(即使最终客户没有将产品添加到购物车 - 这就是为什么我可以不使用钩子:“actionCartSave”)
我可以从钩子 displayAfterProductThumbs 访问这个值 - 但是获取当前值有问题。为了获得正确的价值,我需要:
1)在产品页面选择产品属性(尺寸、颜色)
2)刷新页面触发钩子“displayAfterProductThumbs”
3)读取数据
但我需要它而不刷新。
在文档中,我什么也找不到。试图寻找短语:id_product_attribute、id_combination、idCombination、ipa。关于 id_product_attribute(在 Google 上找到)的大多数信息都与 SEO 相关,并且“出于 SEO 目的,在 url 中包含 id_product_attribute 并不是个好主意”。
嗨@DamianSobkowiak,欢迎来到SO :-)
在 PrestaShop 1.6.x 及更早版本中,您可以使用idProductAttribute
全局 JS 变量检索此 ID 。
在 PrestaShop 1.7.x 版本中,买家选择的产品属性(尺寸、颜色等)ID 存储在group
数组中的变量中,但该变量不再包含相关id_product_attribute
本身。
将产品添加到购物车时,将/controllers/front/CartController.php
调用该文件,您可以在第 366 行看到以下内容:
$this->id_product_attribute = (int)Product::getIdProductAttributeByIdAttributes($this->id_product, Tools::getValue('group'));
您的解决方案可能是:
如果触发此事件,请对您将使用以下代码创建的控制器文件进行 Ajax 调用:
if (isset($_GET['group']) && is_array($_GET['group']) && isset($_GET['id_product'])) { include('config/config.inc.php'); echo (int)Product::getIdProductAttributeByIdAttributes((int)$_GET['id_product'], $_GET['group']); }
不要忘记在进行 ajax 调用时传递group
和id_product
值。
检索 ajax 调用的结果并将 id_product_attribute 存储到一个变量中
我希望这有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句