0
votes

I cannot modify the order price when creating an order programmatically via the Webservice.

1.- I first create the cart:

<carts>
<cart>
    <id>102241</id>
    <id_currency>1</id_currency>
    <id_lang>4</id_lang>
    <associations>
        <cart_rows>
            <cart_row>
                <id_product>40</id_product>
                <id_product_attribute>0</id_product_attribute>
                <id_address_delivery>22265</id_address_delivery>
                <quantity>1</quantity>
            </cart_row>
            <cart_row>
                <id_product>41</id_product>
                <id_product_attribute>587</id_product_attribute>
                <id_address_delivery>22265</id_address_delivery>
                <quantity>3</quantity>
            </cart_row>
        </cart_rows>
    </associations>
    <id_address_delivery>22265</id_address_delivery>
    <id_address_invoice>22265</id_address_invoice>
    <id_customer>17440</id_customer>
    <id_carrier>150</id_carrier>
    <date_add>2021-02-07 11:27:42</date_add>
    <date_udp>2021-02-07 11:27:42</date_udp>
</cart>

2.- Then, with the given cartID, I am creating the order

<orders>
<order>
    <id>39997</id>
    <id_address_delivery>22265</id_address_delivery>
    <id_address_invoice>22265</id_address_invoice>
    <id_cart>102241</id_cart>
    <id_currency>1</id_currency>
    <id_lang>4</id_lang>
    <id_customer>17440</id_customer>
    <id_carrier>150</id_carrier>
    <module>bankwire</module>
    <payment>Mercado Libre</payment>
    <total_paid>50000</total_paid>
    <total_paid_real>50000</total_paid_real>
    <total_products>50000</total_products>
    <total_products_wt>50000</total_products_wt>
    <conversion_rate>1</conversion_rate>
    <associations>
        <order_rows>
            <order_row>
                <product_id>40</product_id>
                <product_attribute_id>0</product_attribute_id>
                <product_quantity>1</product_quantity>
                <product_price>30000</product_price>
                <unit_price_tax_incl>30000</unit_price_tax_incl>
                <unit_price_tax_excl>30000</unit_price_tax_excl>
            </order_row>
            <order_row>
                <product_id>41</product_id>
                <product_attribute_id>587</product_attribute_id>
                <product_quantity>2</product_quantity>
                <product_price>10000</product_price>
                <unit_price_tax_incl>10000</unit_price_tax_incl>
                <unit_price_tax_excl>10000</unit_price_tax_excl>
            </order_row>
        </order_rows>
    </associations>
    <valid>1</valid>
    <current_state>2</current_state>
    <total_discounts>0</total_discounts>
    <total_discounts_tax_incl>0</total_discounts_tax_incl>
    <total_discounts_tax_excl>0</total_discounts_tax_excl>
    <total_paid_tax_incl>50000</total_paid_tax_incl>
    <total_paid_tax_excl>50000</total_paid_tax_excl>
    <total_shipping>0</total_shipping>
    <total_shipping_tax_incl>0</total_shipping_tax_incl>
    <total_shipping_tax_excl>0</total_shipping_tax_excl>
</order>

but, when created, it returns the prices from the store (24990 for productID 40, varID 0) and (24990 for productID 41, varID 587) and not the ones that I defined in the XML. I also tried sending a PUT request afterwards to change them but didn't succeed.

Changinng an order product's price is possible in the back office UI. How can I do this via the webservice?

1

1 Answers

0
votes

What you can or can't do in the Prestashop webservice is defined in an object class variable $webserviceParameters.

Check your Order.php $webserviceParameters. You can see in associations:

'product_price' => array('setter' => false)

'getter' is for getting variables, 'setter' is for updating variables.

'setter' => false means you can't change it.

Override

But you can add an Order.php override: you need to override a function __construct() with $this->webserviceParameters = ... inside it.

And change the webservice parameters by adding a function there, i. e.

'setter' => 'setOrderRowProductPrice'

And then you need to write a function:

function setOrderRowProductPrice($product_price) {
    // $product_price is a variable from XML
    // $this->product_price is a variable from the database
    // Your code (i. e. add changes to the database)
    return $product_price;
}