[checkout] Item pricing - different based on image dimension?

jmn

Joined: 2011-01-12
Posts: 6
Posted: Wed, 2011-01-12 10:19

Hi,

Is there any way to have a price set for different image sizes (e.g. panoramic type, normal type, etc) without having to change each item for the alternate type individually? Ideally it would detect different size automatically but I'd be happy if there was a way to simply save a second set of pricing/options.

Alternatively, if this can't be done in checkout - can anyone recommend a different cart system that will plug into Gallery? Does zencart have this feature?

Cheers,
J

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Wed, 2011-01-12 12:36

There's no way to do that automatically, but you could modify checkout to do it, if you wanted to.

Quote:
I'd be happy if there was a way to simply save a second set of pricing/options.

Obviously there's an easy way to save a second set of pricing/options (use a second product) but you (currently) still have to choose which product(s) apply to which image. Or separate them by album.

 
jmn

Joined: 2011-01-12
Posts: 6
Posted: Thu, 2011-01-13 09:17
alecmyers wrote:
There's no way to do that automatically, but you could modify checkout to do it, if you wanted to.

Quote:
I'd be happy if there was a way to simply save a second set of pricing/options.

Obviously there's an easy way to save a second set of pricing/options (use a second product) but you (currently) still have to choose which product(s) apply to which image. Or separate them by album.

Thanks for the quick response! Yep basically I have ~10 product types for each image type, so I was hoping there would be a quicker way than turning them on and off for each product (of the differing type) rather than clicking the checkboxes individually - thanks for confirming that some code modifications would be need to be made =)

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Thu, 2011-01-13 12:51

It would be a one-line hack (pretty much) to apply even-numbered products to say landscape format pictures, and odd-numbered products to portrait format pictures. The complexity of the code change goes up with how much more sophisticated you want the selectivity to be.

There's an unlimited number of possibilities for different customizations of the whole Gallery2/checkout system and everyone just *knows* that their own requirements are mirrored by a boundless host of other users all (silently) crying out for the same solution ("I can't believe this system doesn't do xyz, surely everyone needs xyz!") Remember php is an interpreted scripting system that anyone can edit with just a text editor; it's not compiled, it doesn't need an expensive development system, and everything is free. That means that it's trivial to change the code to meet your exact requirements. To that extent, G2/checkout already does all the extra features that everyone individually wants, you just need to configure it to do so.

 
jmn

Joined: 2011-01-12
Posts: 6
Posted: Sat, 2011-01-15 03:45

Thanks for the confidence boost. I'm going to give it a go! Haha.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2011-01-15 21:36

The hacky way is to edit function doProductListPlugins(...) in file CheckoutInterfaceHelper.class to adjust the list of products ($products) given whatever you want to determine about the item $itemId.

For instance you can load the item with GalleryCoreApi::loadEntitiesById($itemId), then test whatever you want. Then iterate through the $products array and delete the items you don't want to show.

The non-hacky way is to write a module (which can be as simple as a single file with 8 basic lines of code - I posted the shortest possible module somewhere on this form) that implements and registers a CheckoutProductListInterface_1_0, and put the same logic in your adjustProductList(...) function as part of that implementation. That sounds fearsome, but I think you could do the whole thing in less than 12 lines - let me know if you want more info. It was exactly for purposes such as yours that I put in the CheckoutProductListInterface - it would be nice to know someone found it useful.

 
jmn

Joined: 2011-01-12
Posts: 6
Posted: Tue, 2011-01-18 09:51

Thanks for that! Sorry if this is a stupid question. I believe I understand your post but what I'm having trouble with is the code to determine the format (e.g. panorama or normal, portrait or landscape) of an image. Are there sufficient functions available from the API to test that or will I need to something else? I'm looking at the documentation for loadEntitiesById but not sure if that is the right place.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Tue, 2011-01-18 13:57
Quote:
I'm having trouble with is the code to determine the format (e.g. panorama or normal, portrait or landscape) of an image. Are there sufficient functions available from the API to test that or will I need to something else?

It's not obvious is it? It's also made more complicated because in G2, there's no *requirement* for derivatives or thumbnails to have the same aspect ratio as the main image. The square thumbnails module gives you ... thumbnails (a derivative) with a 1:1 aspect ratio, and if you rotate an image in gallery (but have "keep originals") then your derivatives are different landscape/portrait-wise to the originals. None of which may apply to you - I'm just saying a general solution could be complex!

So you have to decide which derivative (or original) of the image you want to test. Let's say you're going to use the aspect ratio of the "preferred" derivative or the original if there's no "preferred" derivative (the "preferred" derivative is what's displayed if you watermark etc, its use is "preferred" to the original.) There's a handy API function to use, fetchPreferredSource. (Which also works for linked items etc.)

So you might do this:


list ($ret, $item) = GalleryCoreApi::loadEntitiesById($itemId);
if ($ret) {
    return $ret;
}
list ($ret, $bestChoice) = GalleryCoreAip::fetchPreferredSource($item);
if ($ret) {
    return $ret;
}
if ($bestChoice->height == $bestChoice->width) {
    /* square */
    .
    .
} elseif ($bestChoice->height > $bestChoice->width)
    /* portrait */
    .
    .
} else {
    /* landscape */
    .
    .
}

I haven't tested it, and typos are excepted.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Tue, 2011-01-18 14:07

Oh I forgot to say - if you're not sure what's in the $products array, put this line in:

echo "<pre>"; print_r($products); echo"</pre>";
 
jmn

Joined: 2011-01-12
Posts: 6
Posted: Tue, 2011-01-18 23:42

Thank you, that is extremely useful. Hopefully with this and your previous help I can get the solution out =) Much appreciated!!!

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Wed, 2011-01-19 00:00

If you get it working by hacking the file above, and you want to move it into a module of its own (no real need, but it's kind of cute) then I'll give you more info on how to do that too.