protected function ajaxResponse(CompositeJSONResponse $response) { $response->set('orderSummary', SessionOrder::getOrderData()); if ($msg = $this->getMessage()) { $response->set('successMessage', $msg); } if ($error = $this->getErrorMessage()) { $response->set('errorMessage', $error); } return $response; }
public function cartUpdate() { $response = new CompositeJSONResponse(); $response->addAction('miniCart', 'order', 'miniCartBlock'); return $this->ajaxResponse($response); }
protected function getUpdateResponse() { /////// @todo - should be a better way for recalculating taxes... ActiveRecord::clearPool(); $this->config->resetRuntime('DELIVERY_TAX_CLASS'); $this->order = CustomerOrder::getInstanceById($this->order->getID(), true); /////// $this->order->loadAll(); $this->restoreShippingMethodSelection(); ActiveRecordModel::clearArrayData(); if ($paymentMethod = $this->session->get('OrderPaymentMethod_' . $this->order->getID())) { $this->order->setPaymentMethod($paymentMethod); $this->order->getTotal(true); } $this->setAnonAddresses(); // @todo: sometimes the shipping address disappears (for registered users that might already have the shipping address entered before) if (!$this->order->shippingAddress->get() && $this->isShippingRequired($this->order) && $this->user->defaultShippingAddress->get()) { $this->user->defaultShippingAddress->get()->load(); $this->order->shippingAddress->set($this->user->defaultShippingAddress->get()->userAddress->get()); $this->order->shippingAddress->get()->load(); } $response = new CompositeJSONResponse(); $response->addAction('overview', 'onePageCheckout', 'overview'); $response->addAction('cart', 'onePageCheckout', 'cart'); if ($this->request->getActionName() != 'setPaymentMethod') { $response->addAction('payment', 'onePageCheckout', 'payment'); } $response->set('order', $this->getOrderValues($this->order)); foreach (func_get_args() as $arg) { $response->addAction($arg, 'onePageCheckout', $arg); } $this->session->unsetValue('noJS'); $response = $this->postProcessResponse($response); return $response; }
public function create() { $request = $this->getRequest(); $query = $request->get('query'); if (strlen($query)) { $products = $this->getProductsFromSearchQuery($query); } else { $products = new ARSet(); $products->add(Product::getInstanceById((int) $this->request->get('productID'), true)); } $saveResponse = array('errors' => array(), 'items' => array()); $composite = new CompositeJSONResponse(); $order = CustomerOrder::getInstanceByID((int) $this->request->get('orderID'), true); $order->loadAll(); foreach ($products as $product) { if ($product->isDownloadable()) { $shipment = $order->getDownloadShipment(); } else { if ((int) $this->request->get('shipmentID')) { $shipment = Shipment::getInstanceById('Shipment', (int) $this->request->get('shipmentID'), true, array('Order' => 'CustomerOrder', 'ShippingService', 'ShippingAddress' => 'UserAddress', 'Currency')); } } if (empty($shipment)) { $shipment = $order->getShipments()->get(0); } if (!$shipment) { $shipment = Shipment::getNewInstance($order); } if (!$shipment->order->get()) { $shipment->order->set($order); } $history = new OrderHistory($order, $this->user); $existingItem = false; foreach ($shipment->getItems() as $item) { if ($item->getProduct() === $product) { if (!$product->getOptions(true)) { $existingItem = $item; } break; } } if ($existingItem) { $item = $existingItem; if ($product->isDownloadable()) { return new JSONResponse(false, 'failure', $this->translate('_downloadable_item_already_exists_in_this_order')); } else { $item->count->set($item->count->get() + 1); } } else { $currency = $shipment->getCurrency(); $item = OrderedItem::getNewInstance($order, $product); $item->count->set(1); $item->price->set($currency->round($item->reduceBaseTaxes($product->getPrice($currency->getID())))); $order->addItem($item); $shipment->addItem($item); $shipment->save(); } $resp = $this->save($item, $shipment, $existingItem ? true : false); if (array_key_exists('errors', $resp)) { $saveResponse['errors'] = array_merge($saveResponse['errors'], $resp['errors']); } else { if (array_key_exists('item', $resp)) { $saveResponse['items'][] = $resp['item']; } } } // for each product if (count($saveResponse['errors']) == 0) { unset($saveResponse['errors']); } if (isset($saveResponse['errors'])) { $response = new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_unable_to_update_items_quantity')); } else { $response = new JSONResponse($saveResponse, 'success', $this->translate('_item_has_been_successfuly_saved')); } $composite->addResponse('data', $response, $this, 'create'); $ids = array(); foreach ($saveResponse['items'] as $item) { $ids[] = $item['ID']; } $composite->addAction('html', 'backend.orderedItem', 'items'); $this->request->set('item_ids', implode(',', $ids)); $history->saveLog(); return $composite; }
private function getTransactionUpdateResponse() { $response = new CompositeJSONResponse(); $response->addAction('transaction', 'backend.payment', 'transaction'); $response->addAction('totals', 'backend.payment', 'totals'); return $response; }
private function statusResponse($statusMsg, ConfigurationContainer $module) { $response = new CompositeJSONResponse(); $response->setResponse('status', new JSONResponse(array('status' => $this->makeText($statusMsg, array($this->translate($module->getName())))))); $response->addAction('node', 'backend.module', 'node'); return $response; }
public function cartUpdate() { if ($this->order->isMultiAddress->get()) { return new ActionRedirectResponse('order', 'multi'); } else { $response = new CompositeJSONResponse(); $response->addAction('miniCart', 'order', 'miniCartBlock'); if ($this->config->get('POPUP_CART_TYPE') == 'FULL_CART') { $response->addAction('popupCart', 'order', 'cartPopup'); } else { $response->addAction('popupCart', 'order', 'addConfirmation', array('message' => $this->getMessage(), 'err' => $this->getErrorMessage())); } return $this->ajaxResponse($response); } }