Codeigniter购物车助手类——更改“subtotal”值

时间:2022-10-10 07:22:12

I am working with the CI Framework and using the Shopping Cart Class. Which has proved a success so far, Until my user has decided to mess about with it and add postage to the total.

我正在使用CI框架和使用购物车类。到目前为止,它已经被证明是成功的,直到我的用户决定搞砸它,并增加邮费。

So what I'd like to do is add the value of the variable $postage to the subtotal array.

所以我想做的是将变量$邮资的值添加到subtotal数组中。

i.e subtotal is first 111.24, Then it goes to my controller and it adds 4 to the subtotal making it 115.24.

我。e的subtotal第一个是111。24,然后它到我的控制器,它在subtotal上加了4,得到115.24。

My array of data is as follows :

我的数据数组如下:

[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

and $data in the controller is set as follows:

控制器中的$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
        );

But subtotal is only going through as the same as the [price] value in the array.

但是subtotal只与数组中的[price]值相同。

Any ideas how to change this?

有什么办法可以改变这种情况吗?

Thanks

谢谢

2 个解决方案

#1


0  

I would try this and see if it works:

我会尝试一下,看看是否可行:

Change:

变化:

       'subtotal'       => $subtotal

To:

:

       'subtotal'       => $this->input->post('print_cost') + $postage

Or, before the array is set, add this line:

或者,在数组设置之前,添加如下一行:

$subtotal += $postage;

#2


0  

This doesn't seem to be a CodeIgniter question and more of a PHP question, assuming I've grasped what you're after correctly.

这似乎不是一个代码点火器问题,更多的是一个PHP问题,假设我已经正确地理解了您想要的内容。

The issue is that $subtotal is wrong. This isn't the class changing the value, it's just wrong in the first place.

问题是,$subtotal是错误的。这并不是类改变值,它首先是错误的。

By the sounds of it you're just trying to add the price with the postage? This should be very simple: $subtotal = $this->input->post('print_cost') + $this->input->post('ARTWORK_price') + $postage;

听起来你只是想把价钱加邮资?这应该很简单:$subtotal = $ This ->input->post('print_cost') + $ This ->输入->post('ARTWORK_price') + $邮资;

Failing that, do some simple debugging; print out the $subtotal field before declaring the array.

否则,做一些简单的调试;在声明数组之前,打印出$subtotal字段。

#1


0  

I would try this and see if it works:

我会尝试一下,看看是否可行:

Change:

变化:

       'subtotal'       => $subtotal

To:

:

       'subtotal'       => $this->input->post('print_cost') + $postage

Or, before the array is set, add this line:

或者,在数组设置之前,添加如下一行:

$subtotal += $postage;

#2


0  

This doesn't seem to be a CodeIgniter question and more of a PHP question, assuming I've grasped what you're after correctly.

这似乎不是一个代码点火器问题,更多的是一个PHP问题,假设我已经正确地理解了您想要的内容。

The issue is that $subtotal is wrong. This isn't the class changing the value, it's just wrong in the first place.

问题是,$subtotal是错误的。这并不是类改变值,它首先是错误的。

By the sounds of it you're just trying to add the price with the postage? This should be very simple: $subtotal = $this->input->post('print_cost') + $this->input->post('ARTWORK_price') + $postage;

听起来你只是想把价钱加邮资?这应该很简单:$subtotal = $ This ->input->post('print_cost') + $ This ->输入->post('ARTWORK_price') + $邮资;

Failing that, do some simple debugging; print out the $subtotal field before declaring the array.

否则,做一些简单的调试;在声明数组之前,打印出$subtotal字段。