Search code examples
customizationopencart-3

Where is location of renderView function that used in Opencart Journal 3 theme Quick Checkout controller


I am trying to auto add a specific product to cart when visitors added an other specific product to cart on Opencart 3.0.2.0 and Journal 3 theme in Quick Checkout.

I could do it in cart.twig but I couldn't do it in Quick Checkout because I can't find where is renderView function that rendering cart_block in checkout controller.

Related code is bellow;

This code from catalog>controller>journal3>checkout.php.

From line 204 to 215.

    $data['cart_block'] = $this->renderView('journal3/checkout/cart', array(
        'column_image'        => $this->language->get('column_image'),
        'column_name'         => $this->language->get('column_name'),
        'column_model'        => $this->language->get('column_model'),
        'column_quantity'     => $this->language->get('column_quantity'),
        'column_price'        => $this->language->get('column_price'),
        'column_total'        => $this->language->get('column_total'),
        'text_recurring_item' => $this->language->get('text_recurring_item'),
        'button_update'       => $this->language->get('button_update'),
        'button_remove'       => $this->language->get('button_remove'),
        'error_warning'       => $this->language->get('error_stock'),
    ));

Solution

  • One simple but not optimal solution can be like this:

    Go to catalog/controller/checkout/cart.php, find the add method public function add() { then in that add method find the following line of code:

    $this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);
    

    Just below that line of code, you can add the following line of code:

    if($this->request->post['product_id'] ==43){
        $this->cart->add('28',1);
    }
    

    ** Please make changes as per your requirement. The above code means if product id 43 is added then product id 28 gets added automatically, but keep in mind if someone adds two 43 then there will be two 28 products.