Request Reviews v1.0 released.
Request Reviews v1.0 released.
Go to line 143 and find the product array.
Find: 'model' => $result['model'],
After, insert:
'product_id' => $result['product_id'],
'href2' => $this->url->http('checkout/cart'),
Go to line 229 and find: $this->data['order'] = $order;
Insert after: $this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
Open: product/category.tpl (in your template folder)
Add the following code, to the image tag (line 42 in standard template)
Code: Select all
id="image_<?php echo $products[$j]['product_id']; ?>"
Code: Select all
<form action="<?php echo $products[$j]['href2']; ?>" method="post" enctype="multipart/form-data" id="category_product_<?php echo $products[$j]['product_id']; ?>">
<input type="hidden" name="quantity" size="3" value="1" />
<input type="hidden" name="product_id" value="<?php echo $products[$j]['product_id']; ?>" />
<a class="add2cart button" onclick="$('#category_product_<?php echo $products[$j]['product_id']; ?>').submit();" id="category_product_<?php echo $products[$j]['product_id']; ?>"><span><?php echo $button_add_to_cart; ?></span></a>
Also, you might want to split this code up, but it's basic html, so it shouldn't be a problem, if you got this far)
Now to the fun part -> Open module/cart.tpl (in your template folder)
At line 59 and 60 you will find:
Code: Select all
});
});
Code: Select all
$('a.add2cart[class]').each(function() {
var $t = $(this);
$t.removeAttr('onclick')
});
$("a[id^='category_product']").click(function () {
var productIDValSplitter = (this.id).split("_");
var productIDVal = productIDValSplitter[2];
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
dataType: 'html',
data: $('#category_product_'+ productIDVal +' :input'),
success: function (html) {
$('#module_cart .middle').html(html);
},
complete: function () {
var image = $('#image_' + productIDVal).offset();
var cart = $('#module_cart').offset();
$('#image_' + productIDVal).before('<img src="' + $('#image_' + productIDVal).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
params = {
top : cart.top + 'px',
left : cart.left + 'px',
opacity : 0.0,
width : $('#module_cart').width(),
heigth : $('#module_cart').height()
};
$('#temp').animate(params, 'slow', false, function () {
$('#temp').remove();
});
}
});
});
* If you are insecure about where to place the above code, and you haven't made any changes to the original jQuery,
you can replace the whole javascript with this:
Code: Select all
<script type="text/javascript"><!--
$(document).ready(function () {
$('#add_to_cart').replaceWith('<a onclick="" id="add_to_cart" class="button">' + $('#add_to_cart').html() + '</a>');
$('#add_to_cart').click(function () {
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
dataType: 'html',
data: $('#product :input'),
success: function (html) {
$('#module_cart .middle').html(html);
},
complete: function () {
var image = $('#image').offset();
var cart = $('#module_cart').offset();
$('#image').before('<img src="' + $('#image').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
params = {
top : cart.top + 'px',
left : cart.left + 'px',
opacity : 0.0,
width : $('#module_cart').width(),
heigth : $('#module_cart').height()
};
$('#temp').animate(params, 'slow', false, function () {
$('#temp').remove();
});
}
});
});
$('a.add2cart[class]').each(function() {
var $t = $(this);
$t.removeAttr('onclick')
});
$("a[id^='category_product']").click(function () {
var productIDValSplitter = (this.id).split("_");
var productIDVal = productIDValSplitter[2];
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
dataType: 'html',
data: $('#category_product_'+ productIDVal +' :input'),
success: function (html) {
$('#module_cart .middle').html(html);
},
complete: function () {
var image = $('#image_' + productIDVal).offset();
var cart = $('#module_cart').offset();
$('#image_' + productIDVal).before('<img src="' + $('#image_' + productIDVal).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
params = {
top : cart.top + 'px',
left : cart.left + 'px',
opacity : 0.0,
width : $('#module_cart').width(),
heigth : $('#module_cart').height()
};
$('#temp').animate(params, 'slow', false, function () {
$('#temp').remove();
});
}
});
});
});
//--></script>
Request Reviews v1.0 released.
dbstr, just one remark on your great guide in your last post...
</form> is missing!!!!!
I know it's a stupid thing and it is present in previous posts but... I was just following your last instructions and, without </form> closure, things were not obviously well... I was losing my head... then, finally I find out this damned missing part...
many thanks again.
Max
-----------------------------------------------------------------------
My last mods: Partita IVA e CF | Pro EU VAT Number | Sales Agents | Pricelist Pro
-----------------------------------------------------------------------
Also, you would want to change the id's, to get it to w3c validate properly. ;-)
Request Reviews v1.0 released.
I was wondering if you could help me/us again... I would like to insert first lines of product description directly in products list (I already changed the view in order to have only one product for each line, so I have some space to insert description).
What do you think about? Is it something doable easily?
Many thanks in advance, I will be grateful even with some tips.
Max
-----------------------------------------------------------------------
My last mods: Partita IVA e CF | Pro EU VAT Number | Sales Agents | Pricelist Pro
-----------------------------------------------------------------------
Either way, you should open and edit catalog/controller/product/category.php, and find the data array for the product listing.
For, let's say, the first 50 chars, you should just add:
Code: Select all
'description' => substr(strip_tags(html_entity_decode($result['description'])),1,50),
This is just something I found on google, so I'll just give you this, as it's much easier than starting to explain how my own stuff would work!
At the bottom of catalog/controller/product/category.php BEFORE the last } insert this:
Code: Select all
private function shorten_string($string, $wordsreturned)
/* Returns the first $wordsreturned out of $string. If string
contains more words than $wordsreturned, the entire string
is returned.*/
{
$retval = $string; // Just in case of a problem
$array = explode(" ", $string);
/* Already short enough, return the whole thing*/
if (count($array)<=$wordsreturned)
{
$retval = $string;
}
/* Need to chop of some words*/
else
{
array_splice($array, $wordsreturned);
$retval = implode(" ", $array)." ...";
}
return $retval;
}
Code: Select all
'description' => ControllerProductCategory::shorten_string(strip_tags(html_entity_decode($result['description'])),20),
In your view file, simply add
Code: Select all
<?php echo $products[$j]['description']; ?>
Request Reviews v1.0 released.
I'm learning a lot of things too...
Many many thanks, I hope I will be able to repay you in the future!
At the moment... I'm quite good with Excel/VBA programming... and I'm available to help in case of need...
ciao
Max
-----------------------------------------------------------------------
My last mods: Partita IVA e CF | Pro EU VAT Number | Sales Agents | Pricelist Pro
-----------------------------------------------------------------------
I have problem with opencart.
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);
Please advise me and help me to solve this issue. Thank you very much!
Antonio
Please open up your own topic but do not hijjack someone elses.antonio wrote:Antonio
And also DO NOT POST YOUR QUESTION IN MULTIPLE TOPICS!
Norman in 't Veldt
Moderator OpenCart Forums
_________________ READ and Search BEFORE POSTING _________________
Our FREE search: Find your answer FAST!.
[How to] BTW + Verzend + betaal setup.
don't know if you're still following this thread but I had a go @your mods in 1.3.4 & managed to achieve an 'Add To Cart' button on the first product only which would suggest I've put the code in the wrong place as is not repeating for the rest of the array. Would you be so kind as to tell me where I went wrong & also, was wondering if this could be applied to all product listings, not just in Categories - ie: Latest Products & when there are no Sub-Categories.
Thanks.
My table in category.tpl
Code: Select all
<table class="list">
<?php for ($i = 0; $i < sizeof($products); $i = $i + 4) { ?>
<tr>
<?php for ($j = $i; $j < ($i + 4); $j++) { ?>
<td width="25%"><?php if (isset($products[$j])) { ?>
<a href="<?php echo $products[$j]['href']; ?>"><img src="<?php echo $products[$j]['thumb']; ?>" title="<?php echo $products[$j]['name']; ?>" alt="<?php echo $products[$j]['name']; ?>" id="image_<?php echo $products[$j]['product_id']; ?>" /></a><br />
<a href="<?php echo $products[$j]['href']; ?>"><?php echo $products[$j]['name']; ?></a><br />
<span style="color: #999; font-size: 11px;"><?php echo $products[$j]['model']; ?></span><br />
<?php if ($display_price) { ?>
<?php if (!$products[$j]['special']) { ?>
<span style="color: #900; font-weight: bold;"><?php echo $products[$j]['price']; ?></span><br />
<?php } else { ?>
<span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
<form action="<?php echo $products[$j]['href2']; ?>" method="post" enctype="multipart/form-data" id="category_product_<?php echo $products[$j]['product_id']; ?>"><br />Qty:
<input type="input" name="quantity" size="3" value="1" />
<input type="hidden" name="product_id" value="<?php echo $products[$j]['product_id']; ?>" />
<a class="add2cart button" onclick="$('#category_product_<?php echo $products[$j]['product_id']; ?>').submit();" id="category_product_<?php echo $products[$j]['product_id']; ?>"><span><?php echo $button_add_to_cart; ?></span></a></form>
<?php } ?>
<?php } ?>
<?php if ($products[$j]['rating']) { ?>
<img src="catalog/view/theme/default/image/stars_<?php echo $products[$j]['rating'] . '.png'; ?>" alt="<?php echo $products[$j]['stars']; ?>" />
<?php } ?>
<?php } ?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
Try this - I haven't tested it, but it should work:
Code: Select all
<table class="list">
<?php for ($i = 0; $i < sizeof($products); $i = $i + 4) { ?>
<tr>
<?php for ($j = $i; $j < ($i + 4); $j++) { ?>
<td width="25%"><?php if (isset($products[$j])) { ?>
<a href="<?php echo $products[$j]['href']; ?>"><img src="<?php echo $products[$j]['thumb']; ?>" title="<?php echo $products[$j]['name']; ?>" alt="<?php echo $products[$j]['name']; ?>" id="image_<?php echo $products[$j]['product_id']; ?>" /></a><br />
<a href="<?php echo $products[$j]['href']; ?>"><?php echo $products[$j]['name']; ?></a><br />
<span style="color: #999; font-size: 11px;"><?php echo $products[$j]['model']; ?></span><br />
<?php if ($display_price) { ?>
<?php if (!$products[$j]['special']) { ?>
<span style="color: #900; font-weight: bold;"><?php echo $products[$j]['price']; ?></span><br />
<?php } else { ?>
<span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
<?php } ?>
<?php } ?>
<?php if ($products[$j]['rating']) { ?>
<img src="catalog/view/theme/default/image/stars_<?php echo $products[$j]['rating'] . '.png'; ?>" alt="<?php echo $products[$j]['stars']; ?>" />
<?php } ?>
<form action="<?php echo $products[$j]['href2']; ?>" method="post" enctype="multipart/form-data" id="category_product_<?php echo $products[$j]['product_id']; ?>"><br />Qty:
<input type="input" name="quantity" size="3" value="1" />
<input type="hidden" name="product_id" value="<?php echo $products[$j]['product_id']; ?>" />
<a class="add2cart button" onclick="$('#category_product_<?php echo $products[$j]['product_id']; ?>').submit();" id="category_product_<?php echo $products[$j]['product_id']; ?>"><span><?php echo $button_add_to_cart; ?></span></a></form>
<?php } ?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
Request Reviews v1.0 released.
Request Reviews v1.0 released.
dbstr wrote:Yep, I think so.. Give it a try. It's been awhile since I've been messing with this stuff.
It works in my 1.4.0, thanks a lot.
I have a question now. Our website is 'Only show prices when a customer is logged in.' How can I hide the Button and "Qty:" if they haven't log in?
Thanks a lot.
Allen
I know nothing about PHP and SQL, but I still try my best to understand it.
1. EDIT: catalog/view/theme/YOURTHEME/template/product/product.tplallenshea wrote: I have a question now. Our website is 'Only show prices when a customer is logged in.' How can I hide the Button and "Qty:" if they haven't log in?
2. FIND:
Code: Select all
<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;"><?php echo $text_qty; ?>
<input type="text" name="quantity" size="3" value="1" />
<a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
Code: Select all
<?php if ($display_price) { ?>
<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;"><?php echo $text_qty; ?>
<input type="text" name="quantity" size="3" value="1" />
<a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
<?php } ?>
Users browsing this forum: No registered users and 67 guests