Jump to content

Modifiy order shipping cost on AdminOrder controller


TheApprentice

Recommended Posts

Hi,

 

I'm developing a little mod on the order tab to change orders shipping costs. I'm editing AdminOrdersController.php  on function postProcess() (line 404, :D ):

public function postProcess()
{
// If id_order is sent, we instanciate a new Order object
if (Tools::isSubmit('id_order') && Tools::getValue('id_order') > 0)
{
$order = new Order(Tools::getValue('id_order'));
if (!Validate::isLoadedObject($order))
$this->errors[] = Tools::displayError('The order cannot be found within your database.');
ShopUrl::cacheMainDomainForShop((int)$order->id_shop);
}


/* Update shipping cost */
if (Tools::isSubmit('submitShippingCost') && isset($order))
{
$order->updateShippingCost( Tools::getValue('shipping_cost') );
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
}
...
...
...
}

but I dont know why the $order->updateShippingCost( Tools::getValue('shipping_cost'));

does not work, i've checked the $order and its all ok. Also i've checked Order class and the updateShippingCost method and all its okay.

 

 

 

What im doing wrong? 

 

 

 

Link to comment
Share on other sites

Well, I've solved that problem by adding the next:

 

public function postProcess()
{
// If id_order is sent, we instanciate a new Order object
if (Tools::isSubmit('id_order') && Tools::getValue('id_order') > 0)
{
$order = new Order(Tools::getValue('id_order'));
if (!Validate::isLoadedObject($order))
$this->errors[] = Tools::displayError('The order cannot be found within your database.');
ShopUrl::cacheMainDomainForShop((int)$order->id_shop);
}


/* Update shipping cost */
if (Tools::isSubmit('submitShippingCost') && isset($order))
{
$shipping_cost = Tools::getValue('shipping_cost');
$total_shipping_tax_excl = Tools::ps_round(  ( ( $shipping_cost * 100 )/($order->carrier_tax_rate + 100) ), 2 );
$total_shipping_tax_incl = Tools::ps_round( $shipping_cost, 2 );
// Update order shipping
$order->total_shipping_tax_excl = $total_shipping_tax_excl;
$order->total_shipping_tax_incl = $total_shipping_tax_incl;


if ( $order->updateShippingCost( $shipping_cost ) )
{
$order->total_paid_tax_incl = $order->total_paid;
$order->update();
// Update carrier shipping
$order_carrier = new OrderCarrier(Tools::getValue('id_order_carrier'));
$order_carrier->shipping_cost_tax_excl = $total_shipping_tax_excl;
$order_carrier->shipping_cost_tax_incl = $total_shipping_tax_incl;
if ( !$order_carrier->update() )
$this->errors[] = Tools::displayError('The order carrier cannot be updated.');

}
else
$this->errors[] = Tools::displayError('The order cannot be updated.');


Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
}


...
...
}

Hope it will helps somebody on the future !

 

  • Like 2
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...