Shopping cart "Add to cart" URL links problem

chewitt
chewitt's picture

Joined: 2010-01-02
Posts: 3
Posted: Sat, 2010-01-02 06:18

I'm making custom tweaks and hacks to the ebony theme to place an "Add to cart" link in a highslide navigation controller. The code to configure the Highslide popup and controller needs to be in <script></script> tags so it's been inserted into the HTML header via the theme.tpl template. The required class=highslide and on.click event which trigger the popup have been added to image block generation code in album.tpl. Highslide works (more testing in IE still needed) but the "Add to cart" URL generated is picking up the album ID instead of the current image ID, so you add the whole album to the cart instead of the single image you want.

I've acquired the link generation code from the code in album.tpl that's used to insert the cart modules own "add to cart" links that display underneath the thumbnails (which I want to replace with a link in the highslide controller).

This is the link generation code in theme.tpl:

'<li class="highslide-cart">'+
'<a class="highslide-cart" href="{g->url arg1="controller=checkout.AddToCart" arg2="itemId=`$theme.item.id`" arg3="return=/main.php?g2itemId=`$theme.item.id`"}">'+
'<span>Add to Cart</span></a>'+
'</li>'+

which builds the URL: http://foto.chrishewitt.net/main.php?g2_controller=cart.AddToCart&g2_itemId=29&g2_return=%2Falbums%2Falnakheel4%2F&g2_authToken=69cfad686030

but it should be: http://foto.chrishewitt.net/main.php?g2_controller=cart.AddToCart&g2_itemId=47&g2_return=%2Falbums%2Falnakheel4%2F&g2_authToken=69cfad686030

http://foto.chrishewitt.net/albums/alnakheel4/ <= shows the problem. Click on an image and then mouse over to have the custom controller appear - the "add to cart" link is second from right.

I don't necessarily think I have the wrong code generating the URL, but it might be in the wrong place (e.g. wrong template) which might explain why it's picking up the album id instead of image id. However, I don't see a way of adding Javascript (which is needed to customise the controller) anywhere other than the page header via theme.tpl. I'm a competent re-user of other people's ideas and examples 'hacker' rather than a developer so I'm not sure where to go next.

Does anyone have any ideas what n00bish mistake I've made?

Christian

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2010-01-02 14:25

Looks like you're mixing up two modules:

Quote:
{g->url arg1="controller=checkout.AddToCart" ...

and

Quote:
which builds the URL: http://foto.chrishewitt.net/main.php?g2_controller=cart.AddToCart&g2_itemId=...

Read the first important note (in bold type) at the top of the checkout module instructions here:
http://codex.gallery2.org/Gallery2:Modules:checkout

 
chewitt
chewitt's picture

Joined: 2010-01-02
Posts: 3
Posted: Sat, 2010-01-02 19:43

--deleted by chewitt--

 
chewitt
chewitt's picture

Joined: 2010-01-02
Posts: 3
Posted: Sat, 2010-01-02 19:46

re-reading your reply.. it's a cut/paste error on my part when creating the post. The code I'm using is cart.AddToCart and it's the standard cart module so things are right, just giving the wrong result.

I've since relocated the JavaScript stuff into album.tpl but it makes no difference.. $theme.item.id is giving the Album's ID not the current image.

CH

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sun, 2010-01-03 03:31
Quote:
re-reading your reply.. it's a cut/paste error on my part when creating the post.

Ok... regrettably I know nothing about the cart module nor javascript so I don't think I can help in this case - hopefully someone else will be able to assist.