简体   繁体   English

如何在Prestashop购物车中获取和使用自定义值

[英]How to get and use custom values in the Prestashop shopping cart

I am new to Prestashop and not quite familiar with the structure of it, but i did manage to setup a custom product field called quantity_step using a tutorial, which is going to be used by the quantity input to determine the step size. 我是Prestashop的新手,对它的结构不太熟悉,但是我确实使用一个教程设法设置了一个自定义产品字段,称为quantity_step ,该字段将由数量输入用来确定步长。

In the product page template product-add-to-cart.tpl there is absolutely no problem getting the value of my custom field {$product.quantity_step} 在产品页面模板product-add-to-cart.tpl ,获取自定义字段{$product.quantity_step}的值绝对没有问题。

<input
  type="text"
  name="qty"
  id="quantity_wanted"
  value="{$product.quantity_wanted}"
  class="input-group"
  step="{$product.quantity_step}" 
  min="{$product.minimal_quantity}"
  aria-label="{l s='Quantity' d='Shop.Theme.Actions'}"
/>

On the other hand, i can't seem to get it to work in the cart template cart-detailed-product-line.tpl : 另一方面,我似乎无法在购物车模板cart-detailed-product-line.tpl

<input
  class="js-cart-line-product-quantity"
  data-down-url="{$product.down_quantity_url}"
  data-up-url="{$product.up_quantity_url}"
  data-update-url="{$product.update_quantity_url}"
  data-product-id="{$product.id_product}"
  type="text"
  value="{$product.quantity}"
  name="product-quantity-spin"
  step="{$product.quantity_step}"
  min="{$product.minimal_quantity}"
/>

My custom field returns null , while the built in field {$product.minimal_quantity} is working of course. 我的自定义字段返回null ,而内置字段{$product.minimal_quantity}当然可以正常工作。

I have a strong feeling i need to change some file somewhere to add my custom value to the {$product} -object, i just can't find that file, as i don't know what to look for :( 我有一种强烈的感觉,我需要在某个地方更改一些文件以将自定义值添加到{$product} -object,我只是找不到该文件,因为我不知道要寻找什么:(

If it helps, i am using the classic theme. 如果有帮助,我正在使用classic主题。

Thank you! 谢谢!

You are supposed to save the value in the DB when the product is added to the Cart and that will be done in the CartController.php class file in postProcess() function. 当将产品添加到购物车时,应该将值保存在DB中,这将在postProcess()函数中的CartController.php类文件中完成。

My Recommendation: You should create a separate DB table for saving the value of your custom field and leave the default Cart and Product object(s) alone, else you will face some serious issues with the core functionalities of PrestaShop. 我的建议:您应该创建一个单独的数据库表来保存您的自定义字段的值,并保留默认的购物车和产品对象,否则PrestaShop的核心功能将面临一些严重的问题。

Look up in the src/Adapter/Cart/CartPresenter.php method presentProduct I think it is that what are you need. 在src / Adapter / Cart / CartPresenter.php方法presentProduct中查找,我认为这是您需要的。 Just add new parameter to $rawProduct['quantity_step'] = 'value' 只需将新参数添加到$ rawProduct ['quantity_step'] ='value'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM