简体   繁体   English

Drupal 8:仅当用户拥有足够的积分时才添加到购物车

[英]Drupal 8: Only add to cart if user has enough credits

I've a site where transactions are based purely on credits. 我有一个网站,交易完全基于信用。 No actual money is exchanged. 没有实际的金钱被交换。 In such a case, I want to restrict users from adding products to cart if they do not have credits to do so. 在这种情况下,我想限制用户在没有积分的情况下将产品添加到购物车。

In steps of how this should be accomplished, here is the sequence of events which I think should work : 在完成此步骤的步骤中,以下是我认为应该起作用的事件序列:

Whenever somebody tries to add a product : 每当有人尝试添加产品时:

  • Use Rule "Before adding product to cart" 使用规则“将产品添加到购物车之前”
  • I need to get the value of the following : 我需要获取以下值:
    • Get user credits 获取用户积分
    • Get sum of current product + cart value 获取当前产品+购物车价值的总和
  • Check for condition if credits is greater than product + cart. 如果信用额度大于产品+购物车,请检查条件。
  • If true, add product to cart else display "Not enough credits". 如果为true,则将产品添加到购物车,否则显示“信用不足”。

I use the loyalty points module for the user credits. 我将忠诚度积分模块用于用户积分。

How can I set up the rules for this scenario? 如何为这种情况设置规则?

我没有使用模块,而是按照lamp5的建议在commerce_add_to_card_form上使用了custom_validation函数

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

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