Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

restrict users to just order from one category (or manufactorer)

restrict users to just order from one category (or manufactorer)

hi,

i want to restrict users to just order from one category and then checkout before they can order from another category.

example
categories:
monday
theuesday
etc.

client order one product for monday checkout before they can order theusday.
if they order monday and theuesday in one cart they should have a popup echo "pls checkout for one day first (or so)"

i hope it is possible.

grtz Edwin

edensan
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: restrict users to just order from one category (or manufactorer)

Hi Edwin,

I can offer only a partial solution to this, and I am not sure if it's going to be good enough for you. Let me explain how and why.

The biggest problem is that when an item is added to the cart that is usually done by AJAX which means that Chameleon can't really intercept it or prevent it.

Also, even if it was not done by AJAX but caused a full new page request, then that page request would contain the info for adding the product to the cart, BUT the product has not been added to the cart YET. So Chameleon just sees the request but the new product is not in the cart so when Chameleon looks at the cart contents, the new item is not in there...  If the user asks for another page, then by that time the item IS in the cart so Chameleon will see it.

Ok so that's the bad news. Let me tell you how much Chameleon would actually be able to do - maybe this is enough:

1 - Chameleon can get a list of all the categories of the items in the cart (before the current page request, for the reasons above, so it lags by 1 page).

$vm = JomGenius("virtuemart");
$ids = $vm->info("cart_category_ids"); // that's the list of ids

2 - Chameleon can determine if all the categories are the same, or if there's a mixture of categories.

$vm = JomGenius("virtuemart");
$ids = $vm->info("cart_category_ids"); // that's the list of ids
$ids = array_unique($ids);
if (count($ids) > 1) return true; // make rule succeed if there's more than 1 unique category represented

Then in the Succeed action you could put up a popup saying that they need to take something out of their cart.

Now I don't think that's really ideal -- better to try to prevent them from adding things in the first place!

So perhaps you could use this instead:

3 - Detect the categories of items in the cart, and display a message on the page if the user is VIEWING a different category page, or an item in a different category to the one in the cart already.

$vm = JomGenius("virtuemart");
$ids = $vm->info("cart_category_ids"); // that's the list of category ids in the cart
if (count($ids) == 0) return false; // nothing in the cart yet; we don't care what gets put in
$current_viewing_cats = $vm->info("category_ids"); // on a VM category or item page that has a category?
if (!is_array($current_viewing_cats) ) return false; // we're not viewing something that has a VM category
if (count($current_viewing_cats) == 0) return false; // we're not viewing something that has a VM category

// Now we know we have something in the cart already, and we're viewing a category list or product.
// So test to see if any of the categories of the current page/item are NOT represented in the cart.

if ($vm->check("any of category_ids = none of",$ids)) return true;


That's a very cool example of the power of JomGenius to compare 2 lists and determine if any of the items in one of them matches nothing in the other list.

So now in the SUCCEED action you can decide how you want to alert the user. There are lots of options. Here are some possibilities:

1 - use the HTML HEAD include to insert some JS onto the page for a popup
2 - use the HTML HEAD include to insert some CSS code to highlight something on the page, or perhaps disable the "add to cart" buttons
3 - use the HTML find-and-replace functions (in recent releases of Chameleon) to find/replace/insert some text into the page, or remove the "add to cart" buttons


I hope that there's something in here which will suit your purposes.
Best regards,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1696
Total Polls:
6
Total Posts:
5941
Posts this week:
8
User Info:
 
Total Users:
5378
Newest User:
gary9131
Members Online:
0
Guests Online:
172

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked