Author Topic: Need to allow only one product purchase VirtueMart 1.1  (Read 10259 times)

servicefly

  • Beginner
  • *
  • Posts: 17
Re: Need to allow only one product purchase
« Reply #15 on: January 31, 2012, 05:16:05 am »
I'm not sure if this can be done, but I would like a User to login and be redirected to a single product based on their login or a coupon? Example: A User logs in and is redirected to photos of their family at a park to purchase as a digital good. A product is listed under the Photos category which is not visible. Then a user logs in with username & password given by park management or a coupon specific to one product. After login or entering coupon they are redirected to product (family photos). That User is the only one who gets to see the product of their family photos.

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 386
    • AwoDev
Re: Need to allow only one product purchase
« Reply #16 on: March 11, 2014, 17:34:24 pm »
Hello,

Your needs seem quite specific, I dont think something like that exists.  I think you would require the development of a custom plugin which should be able to handle it.
Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate

baqpad

  • Beginner
  • *
  • Posts: 11
Re: Need to allow only one product purchase
« Reply #17 on: February 25, 2015, 20:45:19 pm »
Hello,

I now this is an old post but as my question is related to this one and couldn't find in the forum any other post for this, so here I am.
What if I just want to let people buy from a only one category? Say I sell shoes and shirts. So if someone bought shoes I don't want people to buy shirts aswell.
Any idea for that? Hope to find a bit of help.

Joomla 2.5.28
Virtuemart 2.6.10

Thanks guys

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 386
    • AwoDev
Re: Need to allow only one product purchase
« Reply #18 on: February 27, 2015, 01:46:54 am »
Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate

baqpad

  • Beginner
  • *
  • Posts: 11
Re: Need to allow only one product purchase
« Reply #19 on: February 28, 2015, 09:17:58 am »
Thanks seyi,

Yes, I did found that extension but at first glance thought it was not what I was looking for. Been now in contact with them and will come back with any news.

baqpad

  • Beginner
  • *
  • Posts: 11
Re: Need to allow only one product purchase
« Reply #20 on: March 01, 2015, 18:58:57 pm »
Hi seyi,

Got an answer from daycounts.com but the extension you mentioned doesn't do the trink :(

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 386
    • AwoDev
Re: Need to allow only one product purchase VirtueMart 1.1
« Reply #21 on: March 03, 2015, 18:18:19 pm »
Hello,

I created a plugin which automatically excludes selected countries from buying certain products, can be downloaded here:
https://awodev.com/products#plg_vmproductlocexclude

You can alter it to work for your purpose.  In file vmProductLocExclude.php search for the code around line 113
Code: [Select]
<?php
if(empty($cart->BT)) return;
?>

And right before that add this
Code: [Select]
<?php
if(empty($cart->products)) return;

$categories = array();
foreach($cart->products as $product$categories[$product->virtuemart_category_id] = 1;
if(count($categories)==1) return;

//remove the last item in cart
end($cart->products);         // move the internal pointer to the end of the array
$product_cart_id key($cart->products);
$cart->removeProductCart($product_cart_id);
JFactory::getApplication()->enqueueMessage(JText::_('Can only purchase from 1 category'), 'error');

return;
?>

Then install and enable.  That should limit purchase of products to exactly 1 category.  Not sure how it would react if your products happen to be in multiple categories though.

 
Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate

_Ron

  • Beginner
  • *
  • Posts: 1
  • A beginner
Re: Need to allow only one product purchase VirtueMart 1.1
« Reply #22 on: October 01, 2016, 00:57:47 am »
Updated solution for Virtuemart 3.

File to edit: \components\com_virtuemart\controllers\cart.php
Modify the function "add".
Code: [Select]
public function add() {
$mainframe = JFactory::getApplication();
if (VmConfig::get('use_as_catalog', 0)) {
$msg = vmText::_('COM_VIRTUEMART_PRODUCT_NOT_ADDED_SUCCESSFULLY');
$type = 'error';
$mainframe->redirect('index.php', $msg, $type);
}
$cart = VirtueMartCart::getCart();
if ($cart) {
$virtuemart_product_ids = vRequest::getInt('virtuemart_product_id');
$error = false;
if (count($cart->cartProductsData) == 0) {
$cart->add($virtuemart_product_ids,$error);
if (!$error) {
$msg = vmText::_('COM_VIRTUEMART_PRODUCT_ADDED_SUCCESSFULLY');
$type = '';
} else {
$msg = vmText::_('COM_VIRTUEMART_PRODUCT_NOT_ADDED_SUCCESSFULLY');
$type = 'error';
}
} else {
$msg = 'One item per checkout allowed!';
$type = 'error';
}

$mainframe->enqueueMessage($msg, $type);
$mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart', FALSE));

} else {
$mainframe->enqueueMessage('Cart does not exist?', 'error');
}
}