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')); } }
public function set() { $request = $this->application->getRequest(); $orderedItemID = $request->get('orderedItemID'); $choiceID = $request->get('choiceID'); $optionText = $request->get('optionText'); if (!isset($orderedItemID)) { throw new Exception("Ordered item is required"); } if (!isset($choiceID)) { throw new Exception("Choice item is required"); } //throw new Exception(" response : " . $orderedItemID); //$orderItem = ActiveRecordModel::getInstanceByID('OrderedItem', $orderedItemID, ActiveRecordModel::LOAD_DATA, array('Product')); $orderItem = OrderedItem::getInstanceByID('OrderedItem', $orderedItemID, true, true); $orderItem->load(true); $orderItem->loadOptions(); $product_option_choice = ProductOptionChoice::getInstanceByID($choiceID, true, true); $product_option_choice->load(true); if (!isset($product_option_choice)) { throw new Exception('Option not loaded'); } $choice = $orderItem->addOptionChoice($product_option_choice); $orderItem->save(); $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>'); $response->addChild("message", "Success"); if (isset($choice)) { $choice->load(true); if (isset($optionText)) { $choice->optionText->set($optionText); $choice->save(); } } return new SimpleXMLResponse($response); //good /*$ordered_item = OrderedItemOption::getNewInstance($orderItem,$product_option_choice); $ordered_item->load(true); //$ordered_item->updatePriceDiff(); $ordered_item->save(); throw new Exception('is set --- ');*/ /*$productOption = ProductOption::getInstanceByID($product_option_choice->optionID->get(), true); $productOption->load(true); $choice = $orderItem->getOptionChoice($productOption); if(isset($choice)) { $choice->load(true); $orderItem->removeOptionChoice($choice->choice->get()); $orderItem->save(); //$orderItem->removeOption($productOption); //$orderItem->addOptionChoice($choice); //$orderItem->save(); throw new Exception('is set'); //throw new Exception('is set ' . $choice->choice->get()->option->get()->getID()); } else { //$orderItem->addOption($productOption->option->get()); //$orderItem->addOptionChoice($productOption->getChoiceByID($product_option_choice->ID->get())); //$orderItem->save(); $orderItem->addOptionChoice($product_option_choice); $orderItem->save(); throw new Exception('is not set '); }*/ }