Jump to content

Solved: How To Override Product_Reference Setting In Orderdetail.php?


Recommended Posts

Using Prestashop 1.6.1.2

 

In classes/order/OrderDetail.php we have function create(...) which sets product reference seen on invoice:

 

class OrderDetailCore extends ObjectModel
{

    ...

    /** @var string */
    public $product_reference;

    ...

    protected function create(Order $order, Cart $cart, $product, $id_order_state, $id_order_invoice, $use_taxes = true, $id_warehouse = 0)
    {

        ...

        $this->product_reference = empty($product['reference']) ? null : pSQL($product['reference']);

        ...

    }

}

 

I want to customize the behavior of the reference field on the invoice in override/classes/order/OrderDetail.php:

 

class OrderDetail extends OrderDetailCore
{
    protected function create(Order $order, Cart $cart, $product, $id_order_state, $id_order_invoice, $use_taxes = true, $id_warehouse = 0)
    {
        parent::create($order, $cart, $product, $id_order_state, $id_order_invoice, $use_taxes, $id_warehouse) ;

        ...some code which generates $my_custom_product_reference...

        // next line of code has no effect, the product_reference field doesn't actually get changed

        $this->product_reference = $my_custom_product_reference ;

    }

}

 

I'm a little unclear on OOP in php, but I can kind of see why this doesn't work.  So I'm considering some options...

  • Modify classes/order/OrderDetail.php (PS core mod, upgrade will break)
  • Try to figure out how to get the instance of OrderDetailCore and set $product_reference directly (it's public).
  • Develop a module and hook actionValidateOrder, then modify ps_order_detail.product_reference directly in the database.  I'm not sure how the module can find out the order id or reference when the hook function is called.
  • Override classes/order/OrderHistory.php and directly modify the database when an order's OrderState is set to FLAG_PAID

Any insights or ideas will be much appreciated!

Edited by JuanTomas (see edit history)
Link to comment
Share on other sites

did you try adding save or update?

class OrderDetail extends OrderDetailCore
{
    protected function create(Order $order, Cart $cart, $product, $id_order_state, $id_order_invoice, $use_taxes = true, $id_warehouse = 0)
    {
        parent::create($order, $cart, $product, $id_order_state, $id_order_invoice, $use_taxes, $id_warehouse) ;
        ...some code which generates $my_custom_product_reference...
        // next line of code has no effect, the product_reference field doesn't actually get changed
        $this->product_reference = $my_custom_product_reference;
        $this->save();
    }
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...