您在這裡

[購物車折扣功能]Ubercart Discounts (Alternative)模組 - README檔看不太懂 @@

liaozi's 的頭像
liaozi 在 2011-11-14 (週一) 14:46 發表

我想要在購物車新增一個折價功能,折價的流程都很順利
不過在最後的結帳階段,由於沒有設定Conditional actions,所以在最後的付款時,不會帶入折價

翻了README檔,有個Hooks看不懂,請教一下要如何執行Hooks


Hooks:
------
Allows you to hook into a discount to implement custom logic.

/**
* hook_uc_discount() example
*
* Allows for a discount to be modified when it is being loaded/saved/delted
*
* @param $op The discount operation: load, save, or delete
* @param $arg2 Optional argument. Order object is passed in when discounts for an order are being calculated.
*/
function mymodule_uc_discount($op, &$discount, $arg2 = NULL) {
switch($op) {
case 'delete':
case 'save':
$product_ids = get_product_ids_for_discount_object($discount);
foreach ($product_ids as $nid) {
// do something with each affected node (expire cache, etc.)
}
break;
case 'load':
// Modify a discount to not be applied unless a condition passes
if (!is_null($arg2) && $discount->discount_id == 1 && $order->billing_zone != 1) {
$discount->is_active = FALSE;
}
break;
}
}

/**
* hook_uc_discounts_codes_alter() example
*
* Allows for the discount codes that a customer submits to be altered or for the order
* to be altered based on the discount codes.
*
* @param $order Order object with uc_discounts_codes array set
* @param $context Either 'js_calculate' or 'pane_submit'
*/
function mymodule_uc_discounts_codes_alter($order, $context) {
// Do something if a certain code is entered
foreach ($order->uc_discounts_codes as $code) {
if (strtolower($code) == 'special_code') {
// add another item to the cart, etc.
}
}
}

建一個模組,將這堆程式碼複製進入就可以

沒有看其他程式碼,但我估計 hook_uc_discounts_codes_alter() 在 hook_uc_discount() 之後執行
如果 hook_uc_discount 本身己經有一些處理方式,你可以只用 *_alter

"最後的付款時,不會帶入折價"
可能要修改付款時那個 Hook ?

感謝Kay.L您的回覆
我又翻了一些資料,發現似乎與hook無關 XD
找到這個討論串:http://drupal.org/node/1067440
我的問題同討論串一樣,實施折扣價格後,不會出現折扣
Ubercart Discounts checkout review 階段無法折扣
Ubercart Discounts checkout review 階段無法折扣

模組的README有提到Conditional Actions:
--------------------
Two new conditional actions are implemented which allow an order to interact with discounts:
1. Check the order total after discounts have been applied
2. Check if a discount has been applied to the order

不過我在安裝後卻無出現,看樣子暫時無解了 @@

附帶一提,有使用Ubercart的朋友,應該也需要多少做折扣活動吧,你們的折扣的方案為何呢?
我原本有用coupon的方式,可執行成功,也沒有上述的問題,不過缺點就是消費再還需自行代入coupon碼才行,不太方便
Ubercart Discounts (Alternative)可自訂滿額送(如滿1000送100、滿2000送250...等)或滿額打折,在執行折扣優惠的時候,非常的方便

cogito ergo sum 我思故我在

感謝 Kay.L 幫忙測試
實際的問題是在結帳最後階段出現的
cart/checkout => 沒問題
cart/checkout/review => 折扣金額無法出現

其實這個問題是我在試用信用卡時發現的 @@
好家在我的網站訂單不多,加上信用卡也只是試用

不過似乎找到問題了 :)
在 Checkout settings (/admin/store/settings/checkout/edit/panes)
把 Enter discount codes 打開後方會作用

cogito ergo sum 我思故我在