VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: piffero123 on March 10, 2013, 15:55:17 PM

Title: Single Product Purchase
Post by: piffero123 on March 10, 2013, 15:55:17 PM
Hi and sorry for my bad english.
I'm Roberto from Rome, using Virtuemart 2 and Joomla 2.5
I need to modify the cart code, to set just one product purchase.
The customer should add just one (no digital) product in cart.

In Virtuemart 1, the file was ps_cart.php
Can you tell me the name of same or similar file and directory in Virtuemart 2, and where and how change the code in?
Best regards,
Roberto
Title: Re: Single Product Purchase
Post by: Milbo on March 10, 2013, 19:04:21 PM
FE/helpers/cart.php function add
use something like if count($this->products>0) return false, or so
Title: Re: Single Product Purchase
Post by: piffero123 on March 10, 2013, 20:28:07 PM
Thank you for reply but not yet solution:

This is the piece of code for the function add:

public function add($virtuemart_product_ids=null,&$errorMsg='') {
      $mainframe = JFactory::getApplication();
      $success = false;
      $post = JRequest::get('default');

      if(empty($virtuemart_product_ids)){
         $virtuemart_product_ids = JRequest::getVar('virtuemart_product_id', array(), 'default', 'array'); //is sanitized then
      }

      if (empty($virtuemart_product_ids)) {
         $mainframe->enqueueMessage(JText::_('COM_VIRTUEMART_CART_ERROR_NO_PRODUCT_IDS', false));
         return false;
      }

             
I have added the line at the beginning of that code:


public function add($virtuemart_product_ids=null,&$errorMsg='') {
      $mainframe = JFactory::getApplication();
      $success = false;
      $post = JRequest::get('default');

               
                if (count($this->products>0));
                        return false;
                }

                if(empty($virtuemart_product_ids)){
         $virtuemart_product_ids = JRequest::getVar('virtuemart_product_id', array(), 'default', 'array'); //is sanitized then
      }

      if (empty($virtuemart_product_ids)) {
         $mainframe->enqueueMessage(JText::_('COM_VIRTUEMART_CART_ERROR_NO_PRODUCT_IDS', false));
         return false;
      }   


I don't know if the sintax is correct, but now site is a blank page with: "Parse error: syntax error, unexpected T_FOREACH in .........../home/components/com_virtuemart/helpers/cart.php on line 328

[attachment cleanup by admin]
Title: Re: Single Product Purchase
Post by: piffero123 on March 10, 2013, 22:09:52 PM
No solutions yet...thanks for your attention. If you can I would have the string of code to insert..and the exact place in code.
It is urgent.
Best Regards,
Roberto
Title: Re: Single Product Purchase
Post by: piffero123 on March 11, 2013, 11:03:36 AM
Hi Milbo, any suggestion???
Title: Re: Single Product Purchase
Post by: gunblaze on April 26, 2013, 10:32:26 AM
Sorry if i'm late here.

You can try this:
public function add($virtuemart_product_ids=null,&$errorMsg='') {
      $mainframe = JFactory::getApplication();
      $success = false;
      $post = JRequest::get('default');
      if (count($this->products>0)){
         $mainframe->enqueueMessage(JText::_('COM_VIRTUEMART_CART_ERROR_ONLY_1_PRD', false));
         return false;
      }
      ...


then go to your language file in /language/en-GB/en-GB.com_virtuemart.ini and find: COM_VIRTUEMART_CART_ERROR_NO_PRODUCT_IDS

Add the following line above:

COM_VIRTUEMART_CART_ERROR_ONLY_1_PRD="There can only be 1 product at any 1 time"

This should allow you to only add 1 product at one type to cart
Title: Re: Single Product Purchase
Post by: gunblaze on April 26, 2013, 10:41:37 AM
Apologize, there's a syntax error.

It should be the following:

if(count($this->products)>0){
         $mainframe->enqueueMessage(JText::_('COM_VIRTUEMART_CART_ERROR_ONLY_1_PRD', false));
         return false;
}