获取表中特定大小的产品大小

时间:2016-07-11 17:37:14

标签: codeigniter cart

[Adding all quantity of a specific lbc_type in cart与此主题相关]

我有产品表。在表格中有一个名为pouch_size的列,其值为1和2. 1对于小的等效,2对于小的等效。

现在我只想让系统检查购物车中产品的每个尺寸。

如果购物车的产品包装袋尺寸= 1,则回显小

如果购物车的产品尺寸= 2,则回显大

但是如果购物车的产品包含1号和2号小袋,那么回声就会变大

在我的系统中,我试图在购物车中放入具有不同尺寸的产品。 然后在我的代码中。输出只是对特定产品的小而大的回声

$pouch_qty = 0;
foreach($this->cart->contents() as $item)
{
    $name = $item['name'];
    echo "<br>";
    $id = $item['id'];

    print_r($id);
    echo " "; 
    print_r($name); 
    $data['product'] = $this->PaymentModel->getLBCType($name);
        foreach ($data['product'] as $lbctype) 
        {
            $getLBC = $lbctype->lbc_type;
            $pouchsize= $lbctype->pouch_size;
            $string = strval($pouchsize);// convert int to string
            $combine = $string . $string;
            $split = str_split($string);
                if($getLBC == 'Pouch') //check if lbc_type pouch
                {
                    $pouch_qty += $item['qty'];
                        if($pouch_qty > 2)
                        {
                            echo "more than 2";
                        }
                        else
                        {
                            /* PSEUDO CODE

                            -if in the cart there is only 1 product which pouchsize = 1. echo small
                            -if in the cart there is only 1 product which pouchsize = 2 echo large
                            -but if the cart has a 2 products that have different pouch size. echo small and large.

                             */
                            if($pouchsize =='1' && $pouchsize == '2')//1 small, 2 large
                            {
                                echo " small and large";

                            }
                            else if($pouchsize == '2')
                            {
                                echo " large ";
                            }
                            else
                            {
                                echo " small ";
                            }

                        }
                }
        }

0 个答案:

没有答案