Пример #1
0
 /**
  * @role update
  */
 public function updateAddress()
 {
     $validator = $this->createUserAddressFormValidator();
     if ($validator->isValid()) {
         $order = CustomerOrder::getInstanceByID((int) $this->request->get('orderID'), true, array('ShippingAddress' => 'UserAddress', 'BillingAddress' => 'UserAddress', 'State'));
         $address = UserAddress::getInstanceByID('UserAddress', (int) $this->request->get('ID'), true, array('State'));
         $history = new OrderHistory($order, $this->user);
         $address->loadRequestData($this->request);
         $address->save();
         $history->saveLog();
         if (!$this->request->get('ID')) {
             if (!$order->billingAddress->get()) {
                 $order->billingAddress->set($address);
             }
             if (!$order->shippingAddress->get()) {
                 $order->shippingAddress->set($address);
             }
             $order->save();
         }
         return new JSONResponse(array('address' => $address->toArray()), 'success', $this->translate('_order_address_was_successfully_updated'));
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_error_updating_order_address'));
     }
 }
Пример #2
0
 /**
  * @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');
 }
Пример #3
0
 public function changeCount()
 {
     if ($id = (int) $this->request->get("id", false)) {
         $count = (int) $this->request->get("count");
         $price = (double) $this->request->get("price");
         $item = OrderedItem::getInstanceByID('OrderedItem', $id, true, array('Shipment', 'Order' => 'CustomerOrder', 'ShippingService', 'Currency', 'ShippingAddress' => 'UserAddress', 'Product', 'Category'));
         $item->customerOrder->get()->loadAll();
         $history = new OrderHistory($item->customerOrder->get(), $this->user);
         $item->count->set($count);
         if ($item->price->get() != $price) {
             $item->price->set($item->getCurrency()->round($item->reduceBaseTaxes($price)));
         }
         $shipment = $item->shipment->get();
         $shipment->loadItems();
         if ($shipment->getShippingService()) {
             $shipmentRates = $shipment->getDeliveryZone()->getShippingRates($shipment);
             $shipment->setAvailableRates($shipmentRates);
             $shipment->setRateId($shipment->getShippingService()->getID());
         }
         $shipment->recalculateAmounts();
         $item->customerOrder->get()->save(true);
         $item->save();
         $shipment->save();
         $history->saveLog();
         return new JSONResponse(array('ID' => $item->getID(), 'Shipment' => array('ID' => $shipment->getID(), 'Order' => $item->customerOrder->get()->toFlatArray(), 'isDeleted' => $item->isDeleted(), 'amount' => $shipment->amount->get(), 'downloadable' => !$shipment->isShippable(), 'shippingAmount' => $shipment->shippingAmount->get(), 'total' => (double) $shipment->shippingAmount->get() + (double) $shipment->amount->get() + (double) $shipment->taxAmount->get(), 'taxAmount' => $shipment->taxAmount->get(), 'prefix' => $shipment->getCurrency()->pricePrefix->get(), 'suffix' => $shipment->getCurrency()->priceSuffix->get())), 'success');
     } else {
         return new JSONResponse(false, 'failure', $this->translate('_error_updating_item_quantity'));
     }
 }