[Checkout] Remove Add album to cart from top albums but not sub-albums

Tropical Blue

Joined: 2006-08-12
Posts: 41
Posted: Mon, 2006-08-14 02:09

Hi guys,
I realize I can remove the "Add album to cart" by editing the module.inc file but I would like to do something a little different. Probably not possible at this time but worth a question:

I would like the "Add album to cart" option available to the final sub album that contains actual photos. But I don't want "Add album to cart" to be visible on albums that contain further sub-albums (boy this sounds confusing to me, I doubt it's intelligible to anyone). Mine is still a test-bed site but you can head over to http://72.232.95.34/~smallfri/joomla/index.php?option=com_gallery2&Itemid=28 to see what I'm trying to do. For example I would really like to remove the "Add album to cart" from the "Dogshows" sub-album because when someone clicks on it, it simply takes the user to the cart but doesn't add anything.

Any suggestions greatly appreciated.

-Karl-


Gallery version = 2.1.1 core 1.1.0.1
Module = Checkout Version = 0.1.14
PHP version = 4.4.2 apache
Webserver = Apache/1.3.36 (Unix) mod_jk/1.2.14 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 Database = mysql 4.1.19-standard, lock.system=flock
Toolkits = ArchiveUpload, Exif, Getid3, Thumbnail, Gd
Operating system = Linux leonardo.jumba.net.au 2.6.9-34.0.1.EL #1 Wed May 24 07:40:56 CDT 2006 i686
Default theme = matrix
Browser = Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6

 
Termitenshort
Termitenshort's picture

Joined: 2005-10-09
Posts: 1894
Posted: Mon, 2006-08-14 02:41

That is possible but has a small drawback, overall gallery speed.

Indeed, the links are "calculated" each time a page is displayed and when it's a simple test that occurs in module.inc then the link is displayed very wuickly. When the test get a little more cimplex, the overall gallery seems to be slugish.

Now off with the warning, on with the solution to your problem :-)

In order to do this, you need to edit the module.inc (still)

This is the current function:

    function getItemLinks($items, $wantsDetailedLinks, $permissions) {
	$links = array();
	foreach ($items as $item) {
        //if (GalleryUtilities::isA($item, 'GalleryAlbumItem')) {
            //continue;
        //}
	    if (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])),
		          'params' => array('controller' => 'checkout.AddToCart',
					    'itemId' => $item->getId(),
					    'return' => 1));
	    }
	}

	return array(null, $links);
    }

If you stick this in instead, it shoudl work like you want:

    function getItemLinks($items, $wantsDetailedLinks, $permissions) {
	$links = array();
	foreach ($items as $item) {
        //if (GalleryUtilities::isA($item, 'GalleryAlbumItem')) {
            //continue;
        //}
	    if ($item->getCanContainChildren()) {
              list($ret, $ids) = GalleryCoreApi::fetchChildDataItemIds($item);
            }
            if (isset($permissions[$item->getId()]['checkout.purchase']) && count($ids)>0) {
		$itemTypeNames = $item->itemTypeName();
		$links[$item->getId()][] =
		    array('text' => $this->translate(array('text' => 'Add %s To Cart',
							   'arg1' => $itemTypeNames[0])),
		          'params' => array('controller' => 'checkout.AddToCart',
					    'itemId' => $item->getId(),
					    'return' => 1));
	    }
	}

	return array(null, $links);
    }

Please let us know if the perormance are seriously affected or just slightly :-)

See you !

-------------------------
The Termite - :-) - http://perso.mine.nu/

 
Tropical Blue

Joined: 2006-08-12
Posts: 41
Posted: Fri, 2006-08-18 04:27

Hey Termitenshort you're a Champ! Thanks for that, it works a dream and I can't detect any overhead degredation. - average time to load a page for me prior to mod was around 7 secs and after, around 7 secs. See www.supashotz.com for a look if you want to. I'm still developing it.

 
Termitenshort
Termitenshort's picture

Joined: 2005-10-09
Posts: 1894
Posted: Fri, 2006-08-18 05:01

Cool ... I thought it would be some impact, I guess not :-)

Enjoy !

PS: you site is looking good :):)

-------------------------
The Termite - :-) - http://perso.mine.nu/

 
Tropical Blue

Joined: 2006-08-12
Posts: 41
Posted: Fri, 2006-08-18 05:06

Thanks for that feedback. I have just noticed one small impact which would be good if I could get it fixed:

With your mod I lose the "Add item to cart" on the sidebar and in the item actions list under the photo on the photo page. Without your mod they are present. It's not fatal because they are present on the Items page, but it means a client will need to browse back to the items page to add the photo to the cart instead of being able to do it on the photo page. Am I making sense?

 
Tropical Blue

Joined: 2006-08-12
Posts: 41
Posted: Sun, 2006-08-20 22:49

Anyone got any comments/help about my last little glitch? Other than that, Termitenshort's solution it is great.

 
Termitenshort
Termitenshort's picture

Joined: 2005-10-09
Posts: 1894
Posted: Mon, 2006-08-21 01:20

weird I didn't get notofy of your first comment... anyways.

Can you repeat please :-). I'm not sure I understand correctly. You said that whith the mod it doesn't show the "add to cart" for items ? is that right ?

Let me know
-------------------------
The Termite - :-) - http://perso.mine.nu/

 
Tropical Blue

Joined: 2006-08-12
Posts: 41
Posted: Mon, 2006-08-21 04:30

Hey thanks for responding again Termitenshort.

Your mod works perfectly in blocking the "add to cart" item for top level albums and allowing it to display on the bottom most album and also the items page (the page with the collection of photos on it). However when a user clicks on a photo to look at it separately in higher resolution the "add to cart" option is not available to them on that page, neither on the sidebar nor in the "item actions" list box under the photo.

If it's still not clear perhaps these links will show you what I mean:
In this page all is well, add to cart is available:
http://www.supashotz.com/index.php?option=com_gallery2&Itemid=27&g2_itemId=1026

However if you click on any of the photos, for instance the first one, add to cart is not avaialable:
http://www.supashotz.com/index.php?option=com_gallery2&Itemid=27&g2_itemId=1119

 
Termitenshort
Termitenshort's picture

Joined: 2005-10-09
Posts: 1894
Posted: Mon, 2006-08-21 04:52

oo I see, here is a fix for that:

    function getItemLinks($items, $wantsDetailedLinks, $permissions) {
	$links = array();
	foreach ($items as $item) {
        //if (GalleryUtilities::isA($item, 'GalleryAlbumItem')) {
            //continue;
        //}
	    if ($item->getCanContainChildren()) {
              list($ret, $ids) = GalleryCoreApi::fetchChildDataItemIds($item);
            }
            if (isset($permissions[$item->getId()]['checkout.purchase']) && (count($ids)>0 || !$item->getCanContainChildren())) {
		$itemTypeNames = $item->itemTypeName();
		$links[$item->getId()][] =
		    array('text' => $this->translate(array('text' => 'Add %s To Cart',
							   'arg1' => $itemTypeNames[0])),
		          'params' => array('controller' => 'checkout.AddToCart',
					    'itemId' => $item->getId(),
					    'return' => 1));
	    }
	}

	return array(null, $links);
    }

Let me know if it works for you :-)

Cya
-------------------------
The Termite - :-) - http://perso.mine.nu/

 
Tropical Blue

Joined: 2006-08-12
Posts: 41
Posted: Mon, 2006-08-21 12:29

Yup, that's the one. Thanks heaps Termitenshort.

-Karl-

 
Knilch

Joined: 2009-01-19
Posts: 44
Posted: Thu, 2009-01-22 17:49

As this is nearly my problem I just add it to this thread. Mine is a bit different and with the checkout version 0.4.3 and checkoutemail 0.4.0.

Problem is as follows: I actually don't have the "add album to cart"-button except when I am logged in as administrator where it appears in the sidebar. Even when I tick "show add item to cart everywhere" it won't show up underneath the album (regardless if logged in as admin or not).

The final solution should be like the one listed above: only the last child album with the photos should have the "add album to cart" option but as this thread is already 2.5 years old I hesitate to alter the code of module.inc as it surely has changed by now.

Would anybody please help me?

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Thu, 2009-01-22 18:07

Sounds like a confusion of about three different things.

There are now two different commands: "Add {item} to Cart" and "Add Album to Cart".

Each has a separate permission required to be set for the user, before either of them will appear. If it shows for admin and not for the anonymous user, check your permissions settings for the two "[checkout] purchase ..." permissions as described in the module documentation at http://codex.gallery2.org/Gallery2:Modules:checkout

If you only want albums which contain only photos to have "Add Album to Cart" showing you can do that by giving only those albums the "[checkout] Purchase Album" permission.

Or you're a php type you can probably hack in something like the code above. It won't survive module upgrades though, so make a note of your changes.

Given that permissions are set correctly, the "Add item to Cart" command will always be shown in the list of Item Actions on a photo page or, on an album page, as an Item Action for that album (for instance in the sidebar). The "show add item to cart everywhere" setting only controls whether the relevant "add to cart" command is *also* shown adjacent to each thumbnail on album pages (in which case it acts on the album or photo whose thumbnail is adjacent, as you might expect.)

 
Knilch

Joined: 2009-01-19
Posts: 44
Posted: Thu, 2009-01-22 21:09

Thanks yet again for your help, now I also found out about permissions :). You should actually get paid for your time here, an answer from you takes almost never longer than an hour.

The thing with the album purchase still bothers me, though. It just is no option to change every album on its own as I will have a lot of them so an automatic function would be great.

Although I understand HTML and even programmed a flash site some time ago I never fiddled around with PHP. While I roughly found the passage referred to above it has changed a lot, as I thought.

Is there anyone who could help me change the PHP-code so that it works with the current version of checkout? It should just show the "add album to cart"-button only at the last child album which actually contains the photos. I would be very thankful!

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Thu, 2009-01-22 21:21
Quote:
an answer from you takes almost never longer than an hour.

I'm actually a collective, like Nicolas Bourbaki. He (they?) is much smarter than me, though.

 
Knilch

Joined: 2009-01-19
Posts: 44
Posted: Fri, 2009-01-30 14:07

Just wanted to push that again as I am still keen on finding a solution to my "problem". It would be absolutely great having that feature.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2009-01-30 14:12
Quote:
I am still keen on finding a solution to my "problem".

Sounds like a terrific incentive to learn some php, to me.

 
Knilch

Joined: 2009-01-19
Posts: 44
Posted: Fri, 2009-01-30 21:57

It surely looks like it but I really, really don't want to :). I found gallery to help me get rid of writing HTML each time I upload photos to be sold and to get everything running smoothly without the need to concentrate on these things. This concentration I want to have on my photos.

To learn PHP just to get that album sign working seems a bit odd to me. There was a solution some years ago, why not now :)?

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2009-01-30 22:56
Quote:
To learn PHP just to get that album sign working seems a bit odd to me. There was a solution some years ago, why not now ?

Why not now? Because you're asking someone else to sit down and spend an hour of their time digging through and writing code for you which you could quite easily write yourself. Maybe somebody else will jump in and donate their time to you, but I'm the current maintainer for the module, and I'm saying I'm not going to!

 
Knilch

Joined: 2009-01-19
Posts: 44
Posted: Fri, 2009-01-30 23:19

I don't want to argue over that but it is fact that I don't have the faintest clue of PHP and to actually be able to change that I would really have to dig into that and learn it from scratch.

As I probably won't use PHP in any time soon that would be quite a bummer for that little use.

Three years ago someone helped and did this and I just asked if someone can do that now for me. Maybe someone has even made that for himself and may share it here? I also have invested some time in the checkout module by translating the latest build into German, it's not that I am just sitting here and waiting for sth. to fall from the sky.

I just don't see where learning PHP for changing this one thing is worth it.

But okay, I'll live with it and see how I can steer around it.