Extension "checkout": Go to last Image after click "Add to Cart"

Standard Toaster

Joined: 2008-04-27
Posts: 2
Posted: Tue, 2011-01-04 22:57

Hi everybody

I'm trying for hours to fix a little problem. I'm not a real programmer but can put things together as I need them. :-)

You don't need to know checkout to help me out. Just a little PHP and/or Gallery2 knowledge. ;-)

The aim
---------

I installed the checkout-Plugin in Gallery2. I integrated the Gallery in Typo3 with the appropiate Extension: http://typo3.org/extensions/repository/view/gallery2/current/
Finally I've got almost anything running with checkout - except the way back to the picture after pressing the "add to cart" button.

It's faster for the visitor of the gallery to have all pictures on one page. So there are about 100 pictures on one page listed among each other. Now the customer can scroll down and click on the "Add to cart"-Button of a picture she/he likes. After that the browser add the picture to the cart and jumps back to the top auf the page. If the visitor added picture 70 to cart and wants to go on in this album she/he has to scroll all the way down to picture 70. After a view addings it's getting annoying.

Now what I want checkout to do is going back to the added picture in the "album" view.

my solutions (not finished)
--------------------------------

I've been trying a bit to solve this problem. My possible solution: Extending the "Add to Cart" link with the parameter "#10087" (ID of the Image)

To set the parameter 'id=10087' as an ancher in the code at the picture works easly. I just need the link getting run.

The link for "Add to cart" which is generated by checkout is the following: http://www.domain.ch/199.html?g2_controller=checkout.AddToCart&g2_itemId=10087&g2_return=/199.html?g2_itemId=14&
("199.html" is the typo3 page of the gallery album. The whole thin is working with the Typo3 extension I explained on top)

The link must be: http://www.domain.ch/199.html?g2_controller=checkout.AddToCart&g2_itemId=10087&g2_return=/199.html?g2_itemId=14&#10087
-> This is what I want Gallery2 or Checkout to do in the end. :-)

This link is outputed by the following line in theme/matrix/templates/album.tpl: (near line 122)
{g->block type="core.ItemLinks" item=$child links=$child.itemLinks}

The link itself is generated by the following line in modules/checkout/module.inc: (line 845)

line 845    /**
     * @see GalleryModule::getItemLinks()
     */
    function getItemLinks($items, $wantsDetailedLinks, $permissions) {
	list ($ret, $alwaysShow) = GalleryCoreApi::getPluginParameter('module', 'checkout', 'alwaysShowAddToCart');
	if ($ret) {
	    return $ret;
	}
	$links = array();
	foreach ($items as $item) {
	    if (isset($wantsDetailedLinks[$item->getId()]) || $alwaysShow) {
		if ( ( $item->getCanContainChildren() && isset($permissions[$item->getId()]['checkout.purchaseAlbum'])) 
			|| ( !$item->getCanContainChildren() && isset ($permissions[$item->getId()]['checkout.purchase'])) ) {
		    $itemTypeNames = $item->itemTypeName();
		    $links[$item->getId()][] =
			    array('text' => $this->translate(array('text' => 'Add %s To Cart',
							   'arg1' => $itemTypeNames[0])),
line 862				    'params' => array('controller' => 'checkout.AddToCart',
					    'itemId' => $item->getId(),
line 864					    'return' => 1));
		}
	    }
	}

	return array(null, $links);
    }

If you look at the link you see that every parameter in it is the same as the lines 862 to 864 with a "g2_" before. So I thought I could expand the "'return' => 1" as followed:
'return' => 1.$child.id

This does not work. I guess "1" is a fixed integer which is checked and controlled by an other function in the core of gallery. The code tells this at line 845:

    /**
     * @see GalleryModule::getItemLinks()
     */

Now I'm at the edge of my knowledge and need some help.

Summary of my solution
-----------------------------

If you think this is a bad hack. Yes it is! :D
But I think it will work for me!

I know this would be a nice idea for the Bug tracker of the checkout module. But I need a workaround earlier than the next release of Checkout...

Questions
-----------

1. Do you know a better solution to get my idea work. (chapter "The aim")

2. Do you know how I could expand the link of the "Add to cart" button near the Picture? (http://www.domain.ch/199.html?g2_controller=checkout.AddToCart&g2_itemId=10087&g2_return=/199.html?g2_itemId=14&#10087)

bottom line
--------------

Thank you a lot for your ideas or other possible ways how I reach my aim.

Greetings from Switzerland

Michael

System variables
--------------------

My system variables are as followed. It's German. But I think you get the main things.

Checkout-Version = 0.4.3
Gallery-Version = 2.3.1 Kern 1.3.0.1
API = Core 7.54, Modul 3.9, Motiv 2.6, Eingebettet 1.5
PHP-Version = 5.2.12 cgi-fcgi
Webserver = Apache/2.2.13 (FreeBSD) mod_hcgi/0.7.1 mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2
Datenbank = mysqli 5.1.42-log, lock.system=flock
Werkzeuge = NetPBM
Beschleunigung = none, none
Betriebssystem = FreeBSD 6.4-RELEASE-p8 FreeBSD 6.4-RELEASE-p8
Standard-Motiv = matrix
gettext = Aktiviert
Sprache = de_DE
Browser = Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.18) Gecko/2010021720 Iceweasel/3.0.6 (Debian-3.x)