News:

Support the VirtueMart project and become a member

Main Menu

PayPal integration and custom price modifications

Started by kacie_23, February 11, 2021, 17:19:56 PM

Previous topic - Next topic

kacie_23

I am using virtuemart for a PayPal integration. Based on values in my cart, i am editing and modifying the values for custom pricing.

$this->cart->cartPrices

I am not able to modify the value sent into the Paypal Request Array, as seen in the picture.

I have found a possible clue in helpers/paypalstd.php in line 64: $post_variables['amount'] = $this->total;

And the helpers/paypal.php in line 158 : public function setTotal ($total), where the $this->total is set.

Additionally it seem that the setTotal is getting its value from the cart: $paypalInterface->setTotal($cart->cartPrices['billTotal']);

Since I did change the billTotal ([billTotal] => 287.266) in the cartPrices, this makes the problem even more annoying.

As an additional test i collected the VMModel orders, to check the Order_details:



        $curOrderID = $this->cart->virtuemart_order_id;
$thisOrderByID = $orderModel->getOrder($curOrderID);

$thisOrderByID['details']['BT']->order_total = $totalPriceEuro;
$thisOrderByID['details']['BT']->order_salesPrice = $totalPriceEuro;
$thisOrderByID['details']['BT']->order_subtotal = $totalPriceEuro;



This did not work either :)

Usually I have had great success when overwriting the values this way, and I assume that the values are written somewhere.
Where is this ???


Next step:

When looking at the order number i get from :

$order['details']['BT']->order_number

It changes when I am redirected to the PayPal plugin. If I press the back button, the new order-number I was looking at, is the new ordernumber.



It would be great if someone could help to provide an answer to this question, so that I can determine pricing based on custom values in the cart?


Thank you!

kacie_23

#1
I think that the custom pricing problem is due to a root pattern price that all my products inherit from.
I removed this, and removed all the product prices. No pricing set at all.
Now ...... I am starting from scratch, and with zero prices.

When I try to press the Confirm Purchase button, I am not redirected to paypal due to a non-exixting price.
I am not able to set the price to Zero..... Why not?

I tried to modify the price in the cart based on


        $this->cart->cartPrices[$pkey]['override']=1;
$this->cart->cartPrices[$pkey]['product_override_price'] = $tempValue;


This did not work..

Then I tried to add a new price at 0.00000001, and adding a Custom Field type of "String, is input", and giving it a price of 5 Euro and a value "CutstomPrice".
Nothing happens....

Still a zero price when I try to press the Confirm Purchase button

Then I tried this ......



$session = JFactory::getSession();
$vmCartFromSession = $session->get('vmcart',0,'vm');
$vmCartFromSessionDecoded = (object)json_decode($vmCartFromSession,true);

Resulting in :

Object
(
    [cartProductsData] => Array
        (
            [0] => Array
                (
                    [virtuemart_product_id] => 1002
                    [quantity] => 12
                    [customProductData] => Array
                        (
                            [20] => Array
                                (
                                )
                        )
                )
        )
    [vendorId] => 1
    [lastVisitedCategoryId] => 0
    [virtuemart_shipmentmethod_id] => 1
    [virtuemart_paymentmethod_id] => 0
    [automaticSelectedShipment] =>
    [automaticSelectedPayment] =>
    [order_number] => XXXXXX
    [BT] => Array
        (
           ...
        )
    [ST] => Array
        (
            ...
        )
    [cartfields] => Array
        (
            [customer_note] =>
            [tos] => 1
        )
    [couponCode] =>
    [_triesValidateCoupon] => Array
        (
        )
    [order_language] => en-GB
    [pricesCurrency] => 47
    [paymentCurrency] =>
    [_guest] => 0
    [_inCheckOut] =>
    [_inConfirm] =>
    [_redirected] =>
    [_dataValidated] => xxxxxxxxxxxxxxxxxx
    [_confirmDone] => 1
    [STsameAsBT] => 1
    [selected_shipto] => 0
    [_fromCart] =>
    [layout] => default
    [layoutPath] =>
    [virtuemart_cart_id] => 14
    [orderdoneHtml] =>
    [virtuemart_order_id] => 37
)


As specified here :

https://webkul.com/blog/understanding-manipulating-cart-joomla-virtuemart/


But of course.... the developer does not mention, where and how to enter a custom price, for the Cart......
This cart, similar to the entries in the SQL does not contain any prices.


Do anyone have a simple way of creating a Price, with some kind of modifier, so that the end price in the cart is easily and dynamically changed for the current session?

I belive this question have been asked 1000 times, without any good examples.

Anyone????



pinochico

what is custom price?

Why not put custom price right into product price and thinking about other solution?

I don't understand what do you want :)
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

kacie_23

Thank you for a quick reply pinochico,

I have a plugin that changes the price based on fabrication cost + 20%.
This price is collected from a helper.php in the cart (../cart/default_pricelist.php)

Then I need to modify the prices in the cart........

The reason why I did not change the product price directly, Is mainly because I do not know where.
I have tried multiple places, but without succsess:


        $this->cart->cartPrices[$pkey]['product_price']=$tempValue;
$this->cart->cartPrices[$pkey]['override']=1;
$this->cart->cartPrices[$pkey]['product_override_price'] = $tempValue;

$this->cart->cartPrices[$pkey]['product_price']=$tempValue;
$this->cart->pricesUnformatted[$pkey]['override']=1;
$this->cart->pricesUnformatted[$pkey]['product_override_price'] = $tempValue;


Nothing happens.


I finally got succsess with the  Custom Field type of "String, is input", and giving it a price of 5 Euro and a value "CutstomPrice".
Without any pricing, the final price was 5 Euro.

An entry in the custom data was : [96] => 12022
I have no idea what this means though..... where is this price located? In an SQL entry?


                customProductData] => Array
                        (
                            [20] => Array
                                (
                                )

                            [96] => 12022
                        )


But the main reason for not changing the price directly, was because I belived this will affect other users as well.
Even changing the Custom Field would probably affect other users. Or ????

And what if I change a Custom Field after the payment is done. Will orders collect the value from this custom field?