Author Topic: Payment Method options based on categories or products in cart  (Read 1239 times)

Robert_ITMan

  • Jr. Member
  • **
  • Posts: 114
    • websites developed and managed @ ourfingertips.com
  • VirtueMart Version: 3.2.12 and 3.2.15
For VirtueMart 2 we need Payment Method options based on categories or products in cart. We need it so that the payment method will only be available for the products or categories selected - same as for existing Shopper Group option.

We need to have additional option(s) below 'Shopper Group' selection under the 'Payment Method Information' tab. Will need this to be added to core or a plugin rather than a hack that needs rewriting every update. This can not be further customizing existing payment plugins.

Please help! I see several people asking in the forums but no answers, yet. If I solve this I will post it here.

In looking at the code and trying to build similar to Shopper Group I am lost looking at the following in /administrator/components/com_virtuemart/views/paymentmethod and also looking at duplicating the database table virtuemart_paymentmethod_shoppergroups (maybe something like virtuemart_paymentmethod_category)

view.html.php
Code: [Select]
$this->assignRef('shopperGroupList', ShopFunctions::renderShopperGroupList($payment->virtuemart_shoppergroup_ids, true));

// must be something like this
$this->assignRef('categoryListTree', ShopFunctions::categoryListTree($payment->virtuemart_category_ids, true));

tmpl/edit_edit.php
Code: [Select]
        <?php echo VmHTML::row('raw','COM_VIRTUEMART_PAYMENTMETHOD_FORM_SHOPPER_GROUP'$this->shopperGroupList ); ?>
       
        <?php // must be something similar to this
echo VmHTML::row('raw','COM_VIRTUEMART_CATEGORY_S'$this->categoryListTree ); ?>

       
        <?php // or must be something similar to this ?>
        <tr>
<td class="key">
<?php echo vmText::_('COM_VIRTUEMART_CATEGORY_S'?>
</td>
<td>
<select class="inputbox" id="categories" name="categories[]" multiple="multiple"  data-placeholder="<?php echo vmText::_('COM_VIRTUEMART_DRDOWN_SELECT_SOME_OPTIONS')  ?>" size="10">
<option value=""><?php echo vmText::_('COM_VIRTUEMART_UNCATEGORIZED'?></option>
<?php echo $this->category_tree?>
</select>
</td>
        </tr>
www.ourfingertips.com - websites developed and managed @ ourfingertips

Let me help you make the most of the technology at our fingertips

Robert_ITMan

  • Jr. Member
  • **
  • Posts: 114
    • websites developed and managed @ ourfingertips.com
  • VirtueMart Version: 3.2.12 and 3.2.15
Re: Payment Method options based on categories or products in cart
« Reply #1 on: April 25, 2014, 21:10:32 pm »
I have a work around - it's not pretty, nor is it for very helpful for anyone... but I needed something working right away so this is what I came up with by editing only my template file select_payment.php

/templates/(my-template)/com_virtuemart/cart/select_payment.php
Code: [Select]
<?php if ($this->found_payment_method) {
// only show the full payment method when certain products are in the cart
$pay_full_method_id '4';
// following products ids force full payment
$pay_full_prod_id = array('36','39');
// set the values
$pay_in_full=0;
$pay_options=0;
// get the products in the cart
//echo 'cart product id(s): '; 
foreach ($pay_full_prod_id as $full_prod_id) {
  foreach (
$this->cart->products as $paykey => $payrow) {
  
$prod_id $payrow->cart_item_id;
  
//echo $prod_id;
  
if ($prod_id == $full_prod_id) {
    
//echo ' match ('.$full_prod_id.'), ';
$pay_in_full=$pay_in_full+1;
} else {
    
//echo ' no match, ';
$pay_options=$pay_options+1;
}
  }
}
if (
$pay_options>0) {
  if (
$pay_in_full==1) {
   
$pay_in_full_desc='You have an item in your cart that would give you other payment options if you ordered it separately<br />';
  } elseif (
$pay_in_full>1) {
   
$pay_in_full_desc='You have items in your cart that would give you other payment options if you ordered them separately<br />';
  }
}
    echo 
"<fieldset>";
foreach ($this->paymentplugins_payments as $paymentplugin_payments) {
if (is_array($paymentplugin_payments)) {
foreach ($paymentplugin_payments as $paymentplugin_payment) {
  if ($pay_in_full>0) { // need to hide all but the full payment method
$method_id substr(strstr($paymentplugin_payment,'value='), 71) ;
if ($method_id != $pay_full_method_id) {
      echo 'hide this payment method '.$method_id.'<br />';
  continue;
    } else {
    echo $pay_in_full_desc;
}
  }
  echo $paymentplugin_payment.'<br />';
  }
    }
}
    echo 
"</fieldset>";
    } else {
 echo "<h3>".$this->payment_not_found_text."</h3>";
    }
    
?>

www.ourfingertips.com - websites developed and managed @ ourfingertips

Let me help you make the most of the technology at our fingertips

servlet

  • Jr. Member
  • **
  • Posts: 348
  • Business optimization
    • Фототапети
  • VirtueMart Version: 3.2.2
Re: Payment Method options based on categories or products in cart
« Reply #2 on: September 26, 2014, 21:04:12 pm »
Hello
Good work, but how can I set it for categories?
I am using: Joomla 3.7.2 VM 3.2.2
Он-лайн магазин за фототапети http://mishelfoster.com

skhn123

  • Jr. Member
  • **
  • Posts: 72
  • Almost everything in virtuemart
  • VirtueMart Version: 2.6.6
Re: Payment Method options based on categories or products in cart
« Reply #3 on: October 01, 2014, 09:27:23 am »
Hey i am also looking for something like this so can you tell me if i want to hide a particular payment method on cart view if the user has chosen a cart variant.
for example:
if user select a particular option on product details page then i want to hide COD (standard) payment method from cart.
is it possible.
thanks