/** * Edits the shipping method of the order * @param TinyBrick_OrderEdit_Model_Order $order * @param array $data * @return string */ public function edit(TinyBrick_OrderEdit_Model_Order $order, $data = array()) { $array = array(); $orderStatus = $order->getStatus(); $oldMethod = $order->getShippingDescription() . " - \$" . substr($order->getShippingAmount(), 0, -2); if ($data['customcarrier'] != '' && $data['rateid'] == 'custom') { $order->setShippingMethod('custom'); $order->setShippingDescription($data['customcarrier'] . " - " . $data['customMethod']); } else { if ($data['rateid'] != 'custom') { $shippingRate = Mage::getModel('orderedit/order_address_rate')->getCollection()->addFieldToFilter('rate_id', $data['rateid'])->getFirstItem(); $order->setShippingMethod($shippingRate->getCode()); $order->setShippingDescription($shippingRate->getCarrierTitle() . " - " . $shippingRate->getMethodTitle()); } } if ($data['customPrice'] != '') { $order->setShippingAmount($data['customPrice']); $order->setBaseShippingAmount($data['customPrice']); } else { if ($data['rateid'] != 'custom') { $order->setShippingAmount($shippingRate->getPrice()); } } try { $order->save(); //$newMethod = $order->getShippingDescription()." - $".substr($order->getShippingAmount(),0,-2); $newMethod = $order->getShippingDescription() . " - \$" . $order->getShippingAmount; $results = strcmp($oldMethod, $newMethod); if ($results != 0) { $comment = "Changed shipping method:<br />"; $comment .= "Changed FROM: " . $oldMethod . " TO: " . $newMethod . "<br /><br />"; return $comment; } return true; } catch (Exception $e) { $array['status'] = 'error'; $array['msg'] = "Error updating shipping method"; return false; } return true; }