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

dineshprima

  • Beginner
  • *
  • Posts: 28
Need to allow only one product purchase VirtueMart 1.1
« on: February 23, 2011, 10:10:13 am »
Hello,

In my website i need to allow users only select one product to their cart, multiple products are not allowed to add...so how can i do that using virtuemart...any suggestions??

Thanks
Dinesh

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 407
    • AwoDev
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

dineshprima

  • Beginner
  • *
  • Posts: 28
Re: Need to allow only one product purchase
« Reply #2 on: February 23, 2011, 11:40:51 am »
Thanks for the prompt reply...There is no hack for this freely?

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 407
    • AwoDev
Re: Need to allow only one product purchase
« Reply #3 on: February 23, 2011, 19:02:47 pm »
do you mean 1 in quantity (1 of a and 1 of b) or 1 product only into the cart (1 of either a or b)?
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

dineshprima

  • Beginner
  • *
  • Posts: 28
Re: Need to allow only one product purchase
« Reply #4 on: February 24, 2011, 06:08:49 am »
1 product only into the cart (1 of either a or b)

Only one product will be there in cart..no other products ...because it is a service websites , so users can choose only one service package at a time..

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 407
    • AwoDev
Re: Need to allow only one product purchase
« Reply #5 on: February 24, 2011, 11:44:25 am »
Here is a hack that will do just that.  There are 2 places you need to intercept the cart code. 
1) When adding to the cart:  if there is 1 or more items in the cart, dont add
in www/administrator/components/com_virtuemart/classes/ps_cart.php, in function add, right after
Code: [Select]
<?php
function add(&$d) {
?>
enter this
Code: [Select]
<?php
if($_SESSION['cart']["idx"]>=1) return false;
?>



2) when updating the cart: if updating the quantity to more than 1, dont allow
in same file, inside function update, after this line:
Code: [Select]
<?php
$quantity 
= isset($d["quantity"]) ? (int)$d["quantity"] : 1;
?>
enter this
Code: [Select]
<?php
if($quantity>1$quantity 1;
if(
strtolower($func)=='cartadd') return false;
?>

All done.
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

dineshprima

  • Beginner
  • *
  • Posts: 28
Re: Need to allow only one product purchase
« Reply #6 on: February 25, 2011, 07:40:53 am »
Thank you very very much seyi...it worked for me...love you..

DREK

  • Beginner
  • *
  • Posts: 17
Re: Need to allow only one product purchase
« Reply #7 on: March 29, 2011, 17:46:48 pm »
Thanks it works for me also.

However, I have 1 question.

I want to be able to buy only 1 product but in several quantities. I mean, I click in one product, it goes to the cart. I navigate in the webpage and again click in the same product and it gives me an error.

Any idea to buy ONE TYPE of product but in several quantities?

Regards,

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 407
    • AwoDev
Re: Need to allow only one product purchase
« Reply #8 on: March 30, 2011, 00:52:17 am »
Hi,

The above code is specific for 1 product only.  For one product with multiple quantities, you can try this:

in www/administrator/components/com_virtuemart/classes/ps_cart.php, in function add, right after

Code: [Select]
<?php
function add(&$d) {
?>

enter this

Code: [Select]
<?php
if($_SESSION['cart']["idx"]==0);
elseif(
$_SESSION['cart'][0]["product_id"] != $d['product_id']) return;
?>

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

DREK

  • Beginner
  • *
  • Posts: 17
Re: Need to allow only one product purchase
« Reply #9 on: March 30, 2011, 10:29:24 am »
@ seyi thanks for the answer, it was very helpful.

However, I did it slightly different. I would like to to put a text message anytime someone wants to buy different products. Imagine, if someone has A in the cart and wants to hit buy in B, it wouldn't allow it but I want to alert it with a message (something like: Sorry, but you can only buy 1 type product).

Here's the code. I tried it, it works what I wanted it (buy diff. quantities of ONE product but the text message doesn't appear).

Quote
function add(&$d) {

 
  if($_SESSION['cart']["idx"]>=1) {}
 

  if($_SESSION['cart']["idx"]==0){}
  elseif($_SESSION['cart'][0]["product_id"] != $d['product_id'])

  {
   echo "<script>alert('Error Here');</script>";
   return;
  }


The problem is how to make an alert message withouth using the ALERT in JS?
 
I think it would be something like? $vmLogger->warning( $VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY',false) );  but I am not sure, and I think I am missing something.

Could you please me help me with this one? Or someone else?

Thanks,

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 407
    • AwoDev
Re: Need to allow only one product purchase
« Reply #10 on: March 30, 2011, 13:28:21 pm »
you could try either of these

Code: [Select]
<?php
$vmLogger
->warning'My Error Message' );
$vmLogger->err'My Error Message' );
?>


Be sure to add
Code: [Select]
<?php
global $vmLogger;
?>

before calling 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

DREK

  • Beginner
  • *
  • Posts: 17
Re: Need to allow only one product purchase
« Reply #11 on: March 30, 2011, 15:01:16 pm »
Hello seyi,

Thanks for the answer. I introduced this code:

 
Quote
global $sess, $VM_LANG, $cart, $vmLogger,$func;
 
  if($_SESSION['cart']["idx"]>=1) {}
 
  if($_SESSION['cart']["idx"]==0){}
  elseif($_SESSION['cart'][0]["product_id"] != $d['product_id'])
  {
   
   $vmLogger->warning( 'My Error Message' );
   $vmLogger->err( 'My Error Message' );
return;
  }

With that code, it redirects me to the frontpage of the webpage, without alerting an error message, any idea of how to fix it?

Thanks.

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 407
    • AwoDev
Re: Need to allow only one product purchase
« Reply #12 on: March 31, 2011, 08:48:35 am »
Strange error.  If you look down in the function it is used, for example
Code: [Select]
<?php
if ($quantity 0) {
vmRequest::setVar('product_id'$product_id );
$vmLogger->warning$VM_LANG->_('PHPSHOP_CART_ERROR_NO_NEGATIVE',false) );
return False;
}
?>

you can always try joomla messaging system
Code: [Select]
<?php
$mainframe
->enqueueMessage('My error message','error');
?>

againt, do not forget to add $mainframe to the global variables
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

DREK

  • Beginner
  • *
  • Posts: 17
Re: Need to allow only one product purchase
« Reply #13 on: March 31, 2011, 22:25:24 pm »
Hello seyi,

Thanks a million, it worked this way.

Quote

if($_SESSION['cart']["idx"]>=1) {}
 
  if($_SESSION['cart']["idx"]==0){}
  elseif($_SESSION['cart'][0]["product_id"] != $d['product_id'])
  {
   global $mainframe;
   
   $mainframe->enqueueMessage('Error here!','error');
   return true;
  }

Thanks for all the help
, I really appreciated your effort, and WITHOUT abusing of your time, I have another question which I would appreciate just a light about it.

I'm using K2+VirtueMart with Joomla 1.5.

I have a coupons webpage. My problem is that when my clients go to account maintenance link, they have their order history with no problems. However, when they hit in the product that they bought, that link is associated with virtuemart ID and does not redirect to the K2 ID, which I would like to set. Is that possible?

I would like that my clients could have access to the product description even if those products are not available any more. In their order history, they only can click in virtuemart items, which will redirect them to the cart, rather to the products page..

So, basically clients can go to their order history, and hit in a product and is linked to:

Quote
index.php?option=com_virtuemart&page=shop.product_ details&flypage=flypage.tpl&product_id=8&Itemid=13 5

And I would like that the product would go to:
Quote
index.php?option=com_k2&view=item&id=58

My question is how to call the ID of K2?

Here's the part of the code:
Quote
/www/components/com_virtuemart/themes/simplecheckout/templates/pages/account.order_details.tpl.php - path
// ***** Change guard to use new flag $link_to_product instead of !empty( $product_id )
            if( $link_to_product) {
               echo '<a href="'.$sess->url( $mm_action_url."index.php?page=shop.product_details&product_id=$product_id") .'" title="'.$dbcart->f("order_item_name").'">';
     
              }
              $dbcart->p("order_item_name");
              echo " <div style=\"font-size:smaller;\">" . $dbcart->f("product_attribute") . "</div>"
;

I think that the code should me similarly to K2Mart or something like that, but I wanted to stay with VirtueMart and K2. What's the relation of K2 and VirtueMart and how to fix it in order history?

Thanks in advance and one more time, thanks for the help.


dimcho

  • Beginner
  • *
  • Posts: 1
Re: Need to allow only one product purchase
« Reply #14 on: December 19, 2011, 14:56:16 pm »
Hello,
I need something similar...
In my website I need to allow users to select:
Form category 1 (its obligate): only 1 product
category 2: only 0 or 1
category 3: only 0 or 1
category 4: only 0, 1 or 2
category 5: only 0, 1 or 2
category 6: only 0 or 1

Is this possible?