我必须在购物车中添加一些自定义金额的订单项.商品保存,价格= 0,我的模块计算价格并将订单项添加到购物车/订单,但我不明白如何以编程方式设置价格.
我已经阅读了有关使用规则的内容,但我需要我的模块才能设置/更改价格,而无需调用规则.
我尝试使用实体包装器,我尝试更改使用commerce_product_line_item_new()创建的订单项,但什么都没有,当订单项进入购物车时始终具有原始产品价格(在我的情况下为0).
如何以编程方式更改订单项价格?
到目前为止我的代码看起来像:
// For debugging, this function is called by hook_menu()
function mymodule_test($product_id)
{
global $user;
$user = user_load($user->uid);
$order = commerce_cart_order_load($user->uid);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$product = commerce_product_load($product_id);
$line_item = commerce_product_line_item_new(
$product,
1,
0,
array(
),
'cover'
);
$line_item_wrapper = entity_metadata_wrapper("commerce_line_item", $line_item);
$line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
$line_item_wrapper->commerce_unit_price->value(),
'base_price',
array(
'amount' => 1234,
'currency_code' => 'EUR',
'data' => array(),
),
TRUE
);
$insert_line_item = commerce_cart_product_add($user->uid, $line_item_wrapper->value(), FALSE);
return 'done';
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,我尝试调整在commerce/modules/line_item/commerce_line_item.rules.inc中找到的commerce_line_item_unit_price_amount()的代码,但是这个测试:
<?php
global $user;
$product …Run Code Online (Sandbox Code Playgroud) 我遇到了与此处概述的相同问题,但下面的解决方案不起作用.我确实启用了"商品选项".
我也用这个钩子来改变价格,
function mectronic_get_amount_qty($price, $length) {
//print '<pre>P ' . print_r($price, 1) . '</pre>';
//print '<pre>L ' . print_r($length, 1) . '</pre>';
if ($length >= 1 && $length <= 5) return $price;
elseif ($length >= 6 && $length <= 10) return $price * (1 - 0.166666667);
elseif ($length > 10) return $price * (1 - 0.285714286);
}
Run Code Online (Sandbox Code Playgroud)
我试过了
$entity->commerce_pricing_attributes[$set_id['set_id']][$field_name] = $price;
Run Code Online (Sandbox Code Playgroud)
与#4一样,但它不起作用.
我正在使用Commerce模块套件在Drupal 7中建立一个电子商店.通过商店,每天提供物流服务.
结账过程的一部分是向用户显示具有服务可用性的日历.应显示服务可用的日期,并且用户应该能够在结帐过程中选择一天并转到下一个结帐屏幕.
我想使用Fullcalendar脚本来显示用户的每日可用性:
http://arshaw.com/fullcalendar/
drupal中有一个相关的插件:
https://drupal.org/project/fullcalendar
我能够在我的网站上显示正常的完整日历页面.我真正陷入困境的部分是如何在结帐过程中创建fullcalendar窗格,并将用户选择存储在订单中.
我已尝试使用Commerce extra panes模块添加日历:
https://drupal.org/project/commerce_extra_panes
但是我没有成功.我无法想出一种将fullcalendar块显示为窗格的方法.
我已经阅读了Drupal commerce,fullcalendar模块和商业额外窗格模块的文档,但我仍然无法弄清楚如何将fullcalendar显示为窗格.我也尝试过创建自定义模块,但我无法弄清楚如何以编程方式输出fullcalendar.
有没有人这样做过?有没有办法通过这些模块将这个功能添加到结账流程,还是我应该自己从头开始编写所有这些功能?
我正在尝试将Commerce产品类型绑定到我自己的自定义类型节点(用作显示节点).目标是在尽可能少的地方输入新数据.因此,我正在探索基于规则的创建另一种类型的创建.似乎两个方向都有效.在这两者中,我更喜欢在用户创建自定义类型节点时自动创建Commerce产品,然后该节点将用作产品显示.
我想知道是否有人通过这个选择并且可以推荐这个.此外,commerce_product_display_manager模块是否必要?
Drupal Commerce是否仅在Drupal 7核心上运行,
而不支持Backup核心版本像Drupal 6?
我设置了一个drupal商务网站,我想让管理员处理订单并更改订单状态的功能,然后用户收到一个电子邮件链接,将他重定向到付款页面.这样的事情有可能与电子斗士商业或超级卡车?
注意:uc_payafter在7.x中不起作用
我正在尝试在Drupal 8中安装商务模块,但是出现错误“找不到BC math PHP扩展名”。
我已经搜索了此问题,并尝试了其他操作,例如通过添加'bcmath.scale = 2'来编辑PHP.ini,但是我仍然收到错误消息。
任何帮助,将不胜感激,谢谢。
如何在Drupal commerce-2.x中的表单alter上从product_id加载variants_id?
drupal ×6
drupal-7 ×5
drupal-8 ×2
bcmath ×1
commerce ×1
content-type ×1
drupal-hooks ×1
drupal-rules ×1
ubercart ×1