/** * @role update */ public function delete() { $shipment = Shipment::getInstanceByID('Shipment', (int) $this->request->get('id'), true, array('Order' => 'CustomerOrder')); $shipment->order->get()->loadAll(); $history = new OrderHistory($shipment->order->get(), $this->user); $shipment->delete(); $shipment->order->get()->updateStatusFromShipments(); $shipment->order->get()->save(); $history->saveLog(); return new JSONResponse(array('deleted' => true), 'success'); }
/** * @role update */ public function changeShipment() { if (($id = (int) $this->request->get("id", false)) && ($fromID = (int) $this->request->get("from", false)) && ($toID = (int) $this->request->get("to", false))) { $item = OrderedItem::getInstanceByID('OrderedItem', $id, true, array('Product')); $oldShipment = Shipment::getInstanceByID('Shipment', $fromID, true, array('Order' => 'CustomerOrder', 'ShippingAddress' => 'UserAddress', 'Currency')); $newShipment = Shipment::getInstanceByID('Shipment', $toID, true, array('Order' => 'CustomerOrder', 'ShippingAddress' => 'UserAddress', 'Currency')); $history = new OrderHistory($oldShipment->order->get(), $this->user); $zone = $oldShipment->getDeliveryZone(); if ($oldShipment !== $newShipment) { $oldShipment->loadItems(); $oldShipment->removeItem($item); $newShipment->loadItems(); $newShipment->addItem($item); if ($oldShipment->getShippingService()) { $shipmentRates = $zone->getShippingRates($oldShipment); $oldShipment->setAvailableRates($shipmentRates); $oldShipment->setRateId($oldShipment->getShippingService()->getID()); $oldShipment->save(); } if ($newShipment->getShippingService()) { $shipmentRates = $zone->getShippingRates($newShipment); $newShipment->setAvailableRates($shipmentRates); $newShipment->setRateId($newShipment->getShippingService()->getID()); $newShipment->save(); } $item->save(); if ($newShipment->getSelectedRate() || !$newShipment->getShippingService() || !is_int($newShipment->getShippingService()->getID())) { $item->save(); $oldShipment->recalculateAmounts(); $newShipment->recalculateAmounts(); $oldShipment->save(); $newShipment->save(); $history->saveLog(); return new JSONResponse(array('oldShipment' => array('ID' => $oldShipment->getID(), 'amount' => $oldShipment->amount->get(), 'shippingAmount' => $oldShipment->shippingAmount->get(), 'taxAmount' => $oldShipment->taxAmount->get(), 'total' => (double) $oldShipment->shippingAmount->get() + (double) $oldShipment->amount->get() + (double) $oldShipment->taxAmount->get(), 'prefix' => $oldShipment->getCurrency()->pricePrefix->get(), 'suffix' => $oldShipment->getCurrency()->priceSuffix->get()), 'newShipment' => array('ID' => $newShipment->getID(), 'amount' => $newShipment->amount->get(), 'shippingAmount' => $newShipment->shippingAmount->get(), 'taxAmount' => $newShipment->taxAmount->get(), 'total' => (double) $newShipment->shippingAmount->get() + (double) $newShipment->amount->get() + (double) $newShipment->taxAmount->get(), 'prefix' => $newShipment->getCurrency()->pricePrefix->get(), 'suffix' => $newShipment->getCurrency()->priceSuffix->get(), 'Order' => $newShipment->order->get()->toFlatArray())), 'success', $this->translate('_ordered_item_was_successfully_moved')); } else { return new JSONResponse(array('oldShipment' => array('ID' => $fromID), 'newShipment' => array('ID' => $toID)), 'failure', $this->translate('_this_shipping_service_has_no_available_rates')); } } } else { return new JSONResponse(array('status' => 'failure')); } }