Dear all,
I have problem with opencart version 1.32
Now I want to have "add to cart" button in Home page in my opencart system.
In home.tpl file, I made changes as below:
*********************************************************************
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="product_<?php echo $j;?>">
<td style="align: left; width: 70%">
<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;"><?php echo $text_qty; ?>
<input type="text" name="quantity" size="3" value="1" />
</td>
<td>
<a onclick="$('#product_<?php echo $j;?>').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
<?php
$product_id = $products[$j]['product_id'];
?>
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
</td>
</form>
********************************************************************
It runs OK from the second product in the list. But the first product, It can not add into the cart because of error as below:
**********************************************
Notice: Undefined index: product_id inC:\xampp\htdocs\qsmart\catalog\controller\module\cart.phpon line 57Notice: Undefined index: quantity inC:\xampp\htdocs\qsmart\catalog\controller\module\cart.phpon line 57
**********************************************
The code in line 57 of C:\xampp\htdocs\qsmart\catalog\controller\module\cart.php file as below:
$this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option);
I attached my home.tpl and cart.php file for your reference.
Please advise me and help me to solve this issue. Thank you very much!
Antonio
I have problem with opencart version 1.32
Now I want to have "add to cart" button in Home page in my opencart system.
In home.tpl file, I made changes as below:
*********************************************************************
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="product_<?php echo $j;?>">
<td style="align: left; width: 70%">
<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;"><?php echo $text_qty; ?>
<input type="text" name="quantity" size="3" value="1" />
</td>
<td>
<a onclick="$('#product_<?php echo $j;?>').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
<?php
$product_id = $products[$j]['product_id'];
?>
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
</td>
</form>
********************************************************************
It runs OK from the second product in the list. But the first product, It can not add into the cart because of error as below:
**********************************************
Notice: Undefined index: product_id inC:\xampp\htdocs\qsmart\catalog\controller\module\cart.phpon line 57Notice: Undefined index: quantity inC:\xampp\htdocs\qsmart\catalog\controller\module\cart.phpon line 57
**********************************************
The code in line 57 of C:\xampp\htdocs\qsmart\catalog\controller\module\cart.php file as below:
$this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option);
I attached my home.tpl and cart.php file for your reference.
Please advise me and help me to solve this issue. Thank you very much!
Antonio
Attachments
cart.php file
home.tpl file
Hi Qphoria,
I am deploying in local.
I have followed dbstr's guide at http://forum.opencart.com/viewtopic.php ... 7&start=30 but still meet the error when I click the button "add to cart" in my homepage as below:
If I made followed your guide as:
But I really want it run as in product details page using AJAX animation and I am trying but still can not until now with the above error.
And the count no increase in the cart in the right side, there is still zero product in the cart include the above error.
If you can help me, it is very greate. Thank you very much!
Antonio
I am deploying in local.
I have followed dbstr's guide at http://forum.opencart.com/viewtopic.php ... 7&start=30 but still meet the error when I click the button "add to cart" in my homepage as below:
Notice: Undefined index: product_id in C:\xampp\htdocs\qsmart\catalog\controller\module\cart.php on line 57Notice: Undefined index: quantity in C:\xampp\htdocs\qsmart\catalog\controller\module\cart.php on line 57
If I made followed your guide as:
and everything is OK.If you are wanting to use the ajax animation stuff with it, you will have problems with w3 validation as it triggers on <a id="add_to_cart" which means each add to cart button would have the same id.
Same with the form id of "category_product".
But anyway, if you just want it to submit normal POST style, this worked for me (assuming you added the href2 and product_id to the product array in the category controller):
But I really want it run as in product details page using AJAX animation and I am trying but still can not until now with the above error.
And the count no increase in the cart in the right side, there is still zero product in the cart include the above error.
If you can help me, it is very greate. Thank you very much!
Antonio
I would like to attach the related files for your reference. Thank you!
Antonio
Antonio
You will have to open your catalog/controller/common/home.php and add the following code in the product array
so it will look something like
Code: Select all
'product_id' => $result['product_id'],
Code: Select all
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'name' => $result['name'],
Request Reviews v1.0 released.
Hi dbstr,
Yes, I have the code in my file also but can not and still meet error as I described in the previous post.
Please see my file below:
When I click button "add to cart" in my homepage (homepage.tpl), the error still happens as:
anyone can with any solution to help me for this problem? Thank you very much!
Antonio
Yes, I have the code in my file also but can not and still meet error as I described in the previous post.
Please see my file below:
<?php
class ControllerCommonHome extends Controller {
public function index() {
$this->language->load('common/home');
$this->document->title = sprintf($this->language->get('title'), $this->config->get('config_store'));
$this->document->description = $this->config->get('config_meta_description');
$this->data['text_gift'] = $this->language->get('text_gift');
$this->data['text_model'] = $this->language->get('text_model');
$this->data['text_qty'] = $this->language->get('text_qty');
$this->document->breadcrumbs = array();
$this->document->breadcrumbs[] = array(
'href' => $this->url->http('common/home'),
'text' => $this->language->get('text_home'),
'separator' => FALSE
);
$this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store'));
$this->data['welcome'] = html_entity_decode($this->config->get('config_welcome_' . $this->language->getId()));
$this->data['text_latest'] = $this->language->get('text_latest');
$this->data['text_bestseller'] = $this->language->get('text_bestseller');
$this->data['text_special'] = $this->language->get('text_special');
$this->data['text_price'] = $this->language->get('text_price');
$this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
$this->data['action'] = $this->url->http('checkout/cart');
$this->load->model('catalog/product');
$this->load->model('catalog/review');
$this->load->model('tool/seo_url');
$this->load->helper('image');
$this->data['products'] = array();
foreach ($this->model_catalog_product->getLatestProducts(10) as $result) {
if ($result['image']) {
$image = $result['image'];
} else {
$image = 'no_image.jpg';
}
$rating = $this->model_catalog_review->getAverageRating($result['product_id']);
$special = FALSE;
$discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
if ($discount) {
$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
if ($special) {
$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
}
}
if(isset($result['gift'])){
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'name' => $result['name'],
'model' => $result['model'],
'description' => $result['description'],
'meta_description' => $result['meta_description'],
'rating' => $rating,
'stars' => sprintf($this->language->get('text_stars'), $rating),
'thumb' => image_resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
'zoom' => image_resize($image, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height')),
'price' => $price,
'special' => $special,
'gift' => $result['gift'],
'date_start' => $result['date_start'],
'date_end' => $result['date_end'],
'href' => $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id'])),
'href2' => $this->url->http('checkout/cart')
);
}else{
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'name' => $result['name'],
'model' => $result['model'],
'description' => $result['description'],
'meta_description' => $result['meta_description'],
'rating' => $rating,
'stars' => sprintf($this->language->get('text_stars'), $rating),
'thumb' => image_resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
'price' => $price,
'special' => $special,
'href' => $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id'])),
'href2' => $this->url->http('checkout/cart')
);
}
}
if (!$this->config->get('config_customer_price')) {
$this->data['display_price'] = TRUE;
} elseif ($this->customer->isLogged()) {
$this->data['display_price'] = TRUE;
} else {
$this->data['display_price'] = FALSE;
}
$this->id = 'content';
$this->template = $this->config->get('config_template') . 'common/home.tpl';
$this->layout = 'common/layout';
$this->render();
}
}
?>
When I click button "add to cart" in my homepage (homepage.tpl), the error still happens as:
This is the form in home.tpl:Notice: Undefined index: product_id in C:\xampp\htdocs\qsmart\catalog\controller\module\cart.php on line 57
Notice: Undefined index: quantity in C:\xampp\htdocs\qsmart\catalog\controller\module\cart.php on line 57
The AJAX animation runs well, images go to the cart, but the count didn't increate and the errors as above happens.<form action="<?php echo $products[$j]['href2']; ?>" method="post" enctype="multipart/form-data" id="category_product_<?php echo $products[$j]['product_id'];?>">
<td style="align: left; width: 70%">
<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;"><?php echo $text_qty; ?>
<input type="text" name="quantity" size="3" value="1" />
</td>
<td>
<a onclick="$('#category_product_<?php echo $products[$j]['product_id'];?>').submit();" id="category_product_<?php echo $products[$j]['product_id']; ?>" class="button add2cart"><span><?php echo $button_add_to_cart; ?></span></a></div>
<input type="hidden" name="product_id" value="<?php echo $products[$j]['product_id']; ?>" />
</td>
</form>
anyone can with any solution to help me for this problem? Thank you very much!
Antonio
Who is online
Users browsing this forum: No registered users and 1 guest