Reputation: 1522
Hello guys,
Thanks in advance.
I am new to opencart and am currently developing a shopping cart in opencart and everything was going smoothly but I got stuck, help please
I want to access currently added cart items in checkout.tpl for generating an inquiry form, so I was editing controller/checkout.php and added these lines of code to access product details that are currently in the cart:
//Product detail for Enquiry
$product_data = array();
foreach ($this->cart->getProducts() as $product) {
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['option_value'];
} else {
$value = $this->encryption->decrypt($option['option_value']);
}
$option_data[] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value_id' => $option['product_option_value_id'],
'option_id' => $option['option_id'],
'option_value_id' => $option['option_value_id'],
'name' => $option['name'],
'value' => $value,
'type' => $option['type']
);
}
$product_data[] = array(
'product_id' => $product['product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'download' => $product['download'],
'quantity' => $product['quantity'],
'subtract' => $product['subtract'],
'price' => $product['price'],
'total' => $product['total'],
'tax' => $this->tax->getTax($product['price'], $product['tax_class_id']),
'reward' => $product['reward']
);
}
$data['products'] = $product_data;
and then added a line in checout/checkout.tpl :
foreach ($products as $product)
{
echo 'yes am getting products details';
}
but still getting error: Undefined variable: products ?
Am I doing it right? please correct me.
Upvotes: 4
Views: 5479
Reputation: 15151
What you have done is almost correct, however you've used
$data['products'] = $product_data;
where you should have put
$this->data['products'] = $product_data;
Upvotes: 4