A
A
Anton2015-11-11 05:33:35
Kohana
Anton, 2015-11-11 05:33:35

How to count the number of items in my orders in my profile?

Hello, tell me how to calculate the total number of goods, in my orders in the profile in the full information about my order, there is a number of goods, there may be more than one product, if there are several, how to display a common field, the total number of goods and that there all the number of goods were considered.
Action:

public function action_view() {


        $id = (int) $this->request->param('id');
        $orders = ORM::factory('order', $id);

        $user = Auth::instance()->get_user();

        if ($orders->user_id != $user->id) {
            $this->request->redirect();
        }

        $orders->view = 1;
        $orders->save();
        $products_count = ORM::factory('orderproduct')->where('order_id', '=', $id)->find_all();

        $ids = array();
        foreach($products_count as $item){
            //var_dump($item->product_id);
            $ids[$item->product_id]['count'] = $item->count;
            $ids[$item->product_id]['orderprice'] = $item->orderprice;
            $ids[$item->product_id]['size'] = $item->size;
      
   <b> $ids[$item->product_id]['count'] += $item->count;</b>
        }
        //die;
        if($ids){
            $products = ORM::factory('product')->where('id', 'IN', array_keys($ids))->find_all();
        }


        $status = ORM::factory('status')->find_all();

        $deliveries = ORM::factory('delivery')->find_all();
        $payments = ORM::factory('payment')->find_all();

        $deliveriesArray = array();
        foreach($deliveries as $key => $value){
            $deliveriesArray[$value->id] = $value->name;
        }

        $paymentsArray = array();
        foreach($payments as $key => $value){
            $paymentsArray[$value->id] = $value->name;
        }

        $statusArray = array();
        foreach($status as $key => $value){
            $statusArray[$value->id] = $value->status_name;
        }

        $content = View::factory('index/orders/view')
            ->bind('id', $id)
            ->bind('order', $orders)
            ->bind('statusArray', $statusArray)
            ->bind('status', $status)
            ->bind('deliveries', $deliveriesArray)
            ->bind('payments', $paymentsArray)
            ->bind('products_count', $products_count)
            ->bind('products', $products)
            ->bind('ids', $ids);

        $this->template->site_name = "Мои заказы";
        $this->template->content = $content;

    }

I tried to do it at random, added the example of how the count is in the basket. did not work.
$ids[$item->product_id]['count'] += $item->count;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2015-11-11
@Stalker_RED

1. where $ids = array();to add one more line:
2. Here's the thing

<b> $ids[$item->product_id]['count'] += $item->count;</b>
replace with:
3. Add another one at the end ->bind('total', $total)
If you're lucky, the $total variable will appear in the template.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question