Post by Qphoria » Tue Jul 21, 2009 8:36 am

or just do what i said :)

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by BAJR » Tue Jul 21, 2009 4:11 pm

Right.. I'll give this a go.

For me, as an ASP person, I feel like I am trying to talk in a close language (like French and Italian) where I can understand one word in10 ;D ... though they say that to learn you must have pain! and at least I can order a coffee and really appreciate what you are doing.

seriously,, I think you are all being very kind. I wish here was something I could do to help back, other than donate.

New member

Posts

Joined
Sun Jul 12, 2009 6:17 pm

Post by sdqworm » Mon Jul 27, 2009 2:36 am

hi

I have tried all this and it is working. But i need the ajax effect for the button, i want to add item quickly to the side shopping cart, how do i implement this.

Newbie

Posts

Joined
Mon Jul 27, 2009 2:31 am

Post by BAJR » Wed Jul 29, 2009 12:30 am

Aye.. thanks to the help I got, its working for me too... and I am seeing an increase in sales... but like you... teh ajax add so they don't have to keep coming back to the same category page...

oh boy... it is a dream I have too... if anyone can come up with a solution for this version of Open Cart.. I would be prepared to pay.

New member

Posts

Joined
Sun Jul 12, 2009 6:17 pm

Post by sdqworm » Fri Aug 14, 2009 5:24 am

Any solution

Newbie

Posts

Joined
Mon Jul 27, 2009 2:31 am

Post by needacart » Tue Aug 18, 2009 6:02 am

This worked for me. Thanks for the very excellent instructions.


Can the same thing be done to place add to cart buttons on the homepage product display?

Newbie

Posts

Joined
Fri Jul 10, 2009 9:50 pm

Post by BAJR » Wed Aug 19, 2009 11:14 pm

Thanks and donation sent as well..

I still hold out for teh ajax send to cart from the category pages

one day I hope... beyond me! :)

New member

Posts

Joined
Sun Jul 12, 2009 6:17 pm

Post by Qphoria » Thu Aug 20, 2009 12:18 am

thx for donation :) I will see about helping your ajax project. :P

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dbstr » Tue Sep 08, 2009 8:25 pm

Anyone got it to work with animation?

Imagine I got this code:

Code: Select all

<form action="<?php echo $products[$j]['href2']; ?>" method="post" enctype="multipart/form-data" id="category_product_<?php echo $j; ?>"> 

<input type="hidden" name="quantity" size="3" value="1" /> 
<input type="hidden" name="product_id" value="<?php echo $products[$j]['product_id']; ?>" />

<div class="itemBuy">
        <a onclick="$('#category_product_<?php echo $j; ?>').submit();"><img src="catalog/view/theme/dbstr/stylesheet/images/icons/greenBasket.png" /></a>
</div>
</form>
So should I add an id="add_to_cart_<?php echo $j; ?>" to the <a>? And what should my AJAX code look like then?

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by dbstr » Thu Sep 10, 2009 6:15 am

Forget my last question. I have absolutely no experience with jQuery, but after some research I realised I will have to make a new function for the product listings.

So my new question would be, if anyone got a working solution already, or can help make it? I assume it should be pretty easy, if you know your jQuery.

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by dbstr » Thu Sep 10, 2009 10:29 pm

Sorry for my continously bumping of this thread, just wants to tell that I got it to work. Wasn't really that hard. :D

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by Qphoria » Thu Sep 10, 2009 10:39 pm

Why not share how you did it

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dbstr » Thu Sep 10, 2009 10:50 pm

I will. I just have to test it on the standard template, and write a little guide for adding it. ;-)

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by BAJR » Fri Sep 11, 2009 5:09 pm

This is what I've been waiting for!! :)

New member

Posts

Joined
Sun Jul 12, 2009 6:17 pm

Post by dbstr » Fri Sep 11, 2009 6:48 pm

Open: catalog/controller/product/category.php

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']; ?>"
Add the following code, at around line 51 (standard template):

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>
(Small note: The quantity field is hidden, if you want it to show: change type="hidden" to type="input".
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

    });
});
IN BETWEEN THOSE TWO LINES, insert this: (note: if you are insecure about this part, check the bottom)

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.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by BAJR » Sat Sep 12, 2009 1:18 am

You are an amazing person!

First time!

Thank you so much... this is something that could be added as standard !

I can't thank you enough...!

And thanks to all that have helped.. and of course Open Cart.! ;D

New member

Posts

Joined
Sun Jul 12, 2009 6:17 pm

Post by madimar » Thu Oct 01, 2009 5:35 am

Hey guys, you are great!
dbstr, just one remark on your great guide in your last post...

</form> is missing!!!!! >:D

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
-----------------------------------------------------------------------


User avatar
Active Member

Posts

Joined
Thu Sep 24, 2009 6:27 pm


Post by dbstr » Thu Oct 01, 2009 5:46 am

Sorry about that, my bad.

Also, you would want to change the id's, to get it to w3c validate properly. ;-)

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by madimar » Thu Oct 01, 2009 6:25 pm

Hi dear dbstr...
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
-----------------------------------------------------------------------


User avatar
Active Member

Posts

Joined
Thu Sep 24, 2009 6:27 pm


Post by dbstr » Thu Oct 01, 2009 7:14 pm

Do you want the first N words, or the first N characters?

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),
But since that's not very nice, you could use a function to return the first 50 words instead.

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! :D

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;
    }
And to your data array, add this (line ~143, somewhere)

Code: Select all

'description' => ControllerProductCategory::shorten_string(strip_tags(html_entity_decode($result['description'])),20),
(this returns first 20 words)

In your view file, simply add

Code: Select all

<?php echo $products[$j]['description']; ?>
Hope it works, just did a quick test on a standard installation and it seems to work. Tell me if I forgot something. I got alot of things going on right now (new shipping modules + status sms notification) :D

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am
Who is online

Users browsing this forum: No registered users and 6 guests