Forums / Setup & design / Order 2 products at the same time

Order 2 products at the same time

Author Message

Bertrand Dunogier

Tuesday 12 July 2005 8:55:16 am

I'm running in a funny & tricky problem with eZ Publish 3.6 for an e-commerce site.

The website offers among other things contact lenses. They have various options (doptry, color...). So far, everything's fine. Now the problem is that these options can be chosen differently for both eyes ;)

When someone adds lenses with different options for left & right eye, the same product is ordered twice, with different options, one for each eye.

I don't think it is possible to achieve that out of the box. I was thinking about adding an action to the shop module like AddMultipleItemsToBasket, and transfer 2 object IDS with their respective option when different options are chosen.

Do you see a better approach ? Any suggestion is appreciated.

Mads Ovesen

Wednesday 28 September 2005 6:41:02 am

Hi Bertrand,
I'm in need of the same kind of solution. I have no better solution than the one suggested. It seems like the most reasonable way to do it. Did you make it work??

- Mads

/m

Bertrand Dunogier

Wednesday 28 September 2005 6:55:12 am

Yes, I have a working solution.

It's a light hack on the AddToBasket action. It allows you to define options using a subindex, like

eZOption[set_right][2010]

if eZOption[set_right][2010] and eZOption[set_left][2010] are different, 2 products are added, otherwise one is added.

I can provide you with the patch if you want, but it comes with no warranty ;)

Mads Ovesen

Wednesday 28 September 2005 7:25:50 am

Thanks. I would like to see the patch, so I can modify it to fit my needs.

/m

Xavier Dutoit

Monday 03 October 2005 1:07:15 am

It also would be great if you could post the diff in this thread for later reference...

X+

http://www.sydesy.com

Bertrand Dunogier

Tuesday 04 October 2005 5:00:38 am

Here is the patch for eZ Publish 3.6.0 stable

--- kernel/shop/ezshopoperationcollection.orig.php      2005-10-04 13:50:53.000000000 +0200
+++ kernel/shop/ezshopoperationcollection.php   2005-08-19 14:28:12.000000000 +0200
@@ -88,6 +88,18 @@
             eZDebug::writeError( 'Attempted to add object without price to basket.' );
             return array( 'status' => EZ_MODULE_OPERATION_CANCELED );
         }
+
+        /* Check if options are part of a set */
+        $set = false;
+        foreach ( array_keys( $optionList ) as $optionKey ) {
+            if ( substr( $optionKey, 0, 4 ) == 'set_' ) {
+                $returnStatus = eZShopOperationCollection::addToBasket( $objectID, $optionList[$optionKey] );
+                $set = true;
+            }
+        }
+        if ( $set )
+            return array( 'status' => $returnStatus );
+
         $basket =& eZBasket::currentBasket();
 
         /* Check if the item with the same options is not already in the basket: */