[英]Codeigniter Shopping Cart Helper Class - Change the “subtotal” value
我正在使用CI框架並使用購物車類。 到目前為止,這已經證明是成功的,直到我的用戶決定對其進行修改並增加郵資為止。
所以我想做的就是將變量$ postage的值添加到小計數組中。
即小計首先是111.24,然后轉到我的控制器,將小計加4使其成為115.24。
我的數據數組如下:
[id] => 9
[qty] => 1
[price] => 111.24
[price_artwork] =>
[name] => Lincoln Catherdral
[print_type] => Canvas
[postage] => 4
[file_name] => bbb5359bd6d0dc27ace3f2921460a021
[file_ext] => .jpg
[subtotal] => 111.24
控制器中的$ data設置如下:
$data = array(
'id' => $this->input->post('ARTWORK_id'),
'qty' => 1,
'price' => $this->input->post('print_cost'),
'price_artwork' => $this->input->post('ARTWORK_price'),
'name' => $this->input->post('ARTWORK_title'),
'print_type' => $this->input->post('print_type'),
'postage' => $postage,
'file_name' => $this->input->post('ARTWORK_file_name'),
'file_ext' => $this->input->post('ARTWORK_file_ext'),
'subtotal' => $subtotal
);
但是小計只與數組中的[price]值相同。
任何想法如何改變這一點?
謝謝
我會嘗試一下,看看是否可行:
更改:
'subtotal' => $subtotal
至:
'subtotal' => $this->input->post('print_cost') + $postage
或者 ,在設置數組之前,添加以下行:
$subtotal += $postage;
假設我已正確理解您的要求,那么這似乎不是CodeIgniter問題,而更多是PHP問題。
問題是$subtotal
是錯誤的。 這不是改變值的類,首先是錯誤的。
聽起來,您只是想在郵費中加上價格? 這應該非常簡單: $subtotal = $this->input->post('print_cost') + $this->input->post('ARTWORK_price') + $postage;
如果失敗,則進行一些簡單的調試; 在聲明數組之前打印出$subtotal
字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.