我正在尝试为 Hybris Commerce b2c 中的 addtocart 函数添加自定义值。是带有复选框的 boolean 值。
我已在 core-items.xml 中添加了 bol 自定义值,但现在我需要在选中复选框时获取该值,然后再按 addToCart 按钮,然后在结帐页面中显示该值。
我认为这不是一个短任务,但我只是想了解这种过程的数据流,这是复杂的部分。
如果有人有时间解释一些事情,那就太好了!谢谢 !
<form:form method="post" id="addToCartForm" class="add_to_cart_form" action="${addToCartUrl}">
<div>
<div class="custom-control custom-checkbox">
<input path="trasiego" onclick="ACC.productDetail.enableMinusBtn()" type="checkbox" class="custom-control-input" id="trasiego">
<form:checkbox path="trasiego" value="true"/>
<spring:theme code="product.pdp.pedidoTrasiego"/>
</div>
</div>
<input type="hidden" maxlength="3" size="1" id="qty" name="qty" class="qty js-qty-selector-input" value="1">
<input class = "js-simulate-validate-link" type="hidden" name="productCodePost" value="${fn:escapeXml(product.code)}"/>
<ycommerce:testId code="simulateButton">
<button id="simulateButton" type="button" data-error-simulate-url="${fn:escapeXml(simulatePopup)}" data-simulate-title="<spring:theme code="text.simulate"/>" class="btn btn-default btn-block js-add-to-cart" disabled=disabled">
<spring:theme code="basket.simulate"/>
</button>
</ycommerce:testId>
<ycommerce:testId code="addToCartButton">
<button id="addToCartButton" type="submit" class="btn btn-primary btn-block" disabled=disabled>
<spring:theme code="basket.buy"/>
</button>
<br>
</ycommerce:testId>
</form:form>
最佳答案
如果您觉得有帮助,请阅读以下几点,
I've add the bol custom value in core-items.xml......
当我读到上面的声明时有点困惑,因此想指出接触 OOB 扩展代码库是违反标准做法的。相反,您应该在项目中生成自定义扩展并扩展/更新项目 $extension-items.xml
I need to get that value when the checkbox is selected before press the addToCart Button and then show that value in the checkout page.
您可以通过以下步骤实现:
第 1 步 - 在项目扩展 $extension-items.xml 中,向 AbstractOrder 添加一个新的 boolean 属性
<itemtype code="AbstractOrder" autocreate="false" generate="false" >
<attributes>
<attribute qualifier="code" type="java.lang.Boolean">
<persistence type="property" />
</attribute>
</attribute>
</itemtype>
第 2 步 - 运行 ant clean all
第 3 步 - 在您的项目店面扩展中,在 Jsp/Tag 文件中添加一个复选框
步骤 4 - 如果您想在选择/取消选择此复选框时保留此值的选择,您可以在相应的 JS 文件中编写 onClick() 事件。 在你的情况下你可以使用 /$storefornt-extension/web/webroot/WEB-INF/_ui-src/responsive/lib/ybase-0.1.0/js/acc.cart.js
第 5 步 - 在 Controller (MVC) 中创建相应的处理程序。您可以根据需要使用 AddToCartController.java 或 CartPageController
第6步-在相应的facade-->服务中,将新的字段值保存到模型中
第 7 步 - 在 AbstractOrderPopulator 或 CartPopulator 中,映射新字段以将其填充回项目模型中的 CartData。并且可以在下一页上使用相同的 View 。
这样,您的字段值将被持久化并获取以在各个 hybris 层之间传输,并且您可以使用相应的数据对象。
希望有帮助。
关于java - 在 Hybris Commerce 上的 AbstractOrder 中添加自定义值 - AddtoCartFunction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58507484/