plgVmPaymentPagseguro issues

Please post your issues and questions about One Page Checkout for Virtuemart 2 to this forum.

plgVmPaymentPagseguro issues

Postby admin » Mon May 20, 2013 6:39 pm

Dear friends, in case you are based in Brasil and you'd like to use Pageseguro payment plugin, we recommend following fix in case you have issues with OPC + Awo coupons + this plugin.

search for a function retornaHtmlPagamento within your \plugins\vmpayment\pagseguro\pagseguro.php

locate this line:
Code: Select all
// desconto do pedido
        $order_discount = (float)$order["details"]["BT"]->order_discount;


and add/change to this:
Code: Select all
              // desconto do pedido
               $order_discount = (float)$order["details"]["BT"]->order_discount;
      if (empty($order_discount) && (!empty($order["details"]["BT"]->coupon_discount)))
      {
       $order_discount = (float)$order["details"]["BT"]->coupon_discount;
      }
      $order_discount = (-1)*abs($order_discount);
      if (!empty($order_discount))
       {
         $html .= '<input type="hidden" name="extras" value="'.number_format($order_discount, 2, ",", "").'" />';
       }


locate next few lines with foreach loop:
Code: Select all
foreach ($order['items'] as $p) {
         $i++;
            $valor_produto = $p->product_final_price;
            // desconto do pedido
         
            if ($order_discount != 0) {
                $valor_item = $valor_produto - (($valor_produto/$order_subtotal) * $order_discount);
            } else {
                $valor_item = $valor_produto;
            }

          $product_attribute = strip_tags(VirtueMartModelCustomfields::CustomsFieldOrderDisplay($p,'FE'));
         $html .='<input type="hidden" name="item_id_' . $i . '" value="' . $p->virtuemart_order_item_id . '">
            <input type="hidden" name="item_descr_' . $i . '" value="' . $p->order_item_name . '">
            <input type="hidden" name="item_quant_' . $i . '" value="' . $p->product_quantity . '">
            <input type="hidden" name="item_valor_' . $i . '" value="' . number_format($p->product_final_price, 2, ",", "") .'">
            <input type="hidden" name="item_peso_' . $i . '" value="' . ShopFunctions::convertWeigthUnit($p->product_weight, $p->product_weight_uom, "GR") . '">';
      }


update to this:
Code: Select all
foreach ($order['items'] as $p) {
         $i++;
            $valor_produto = $p->product_final_price;
                $valor_item = $valor_produto;
          $product_attribute = strip_tags(VirtueMartModelCustomfields::CustomsFieldOrderDisplay($p,'FE'));
         $html .='<input type="hidden" name="item_id_' . $i . '" value="' . $p->virtuemart_order_item_id . '">
            <input type="hidden" name="item_descr_' . $i . '" value="' . $p->order_item_name . '">
            <input type="hidden" name="item_quant_' . $i . '" value="' . $p->product_quantity . '">
            <input type="hidden" name="item_valor_' . $i . '" value="' . number_format($p->product_final_price, 2, ",", "") .'">
            <input type="hidden" name="item_peso_' . $i . '" value="' . ShopFunctions::convertWeigthUnit($p->product_weight, $p->product_weight_uom, "GR") . '">';
      }


Note:
The original code applied the coupon discount to every single product's price but not to the shipping or payment fee which may have resulted to a wrong total within the payment gateway. Secondly the payment plugin expected order_discount to be set for each order, but this may not be true in all cases, therefore we've changed it accordingly.
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Return to One Page Checkout for Virtuemart 2