Exemplo n.º 1
0
 public function filter($emptyListIsException = false)
 {
     $request = $this->application->getRequest();
     $parser = $this->getParser();
     $apiFieldNames = $parser->getApiFieldNames();
     $parser->loadDataInRequest($request);
     $f = new ARSelectFilter();
     $id = $request->get('ID');
     if (!empty($id)) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('ProductVariation', 'ID'), $id));
     } else {
         throw new Exception('Product variation ID is required');
     }
     $product_variations = ActiveRecordModel::getRecordSetArray('ProductVariation', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($emptyListIsException && count($product_variations) == 0) {
         throw new Exception('Product variation not found');
     }
     while ($variation = array_shift($product_variations)) {
         $xml = $response->addChild('product_variation');
         foreach ($variation as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xml->addChild($k, $v);
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 2
0
 public function filter($emptyListIsException = false)
 {
     $request = $this->application->getRequest();
     $parser = $this->getParser();
     $apiFieldNames = $parser->getApiFieldNames();
     $parser->loadDataInRequest($request);
     $f = new ARSelectFilter();
     $id = $request->get('ID');
     if (intval($id) > 0) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('NewsPost', 'ID'), $id));
     }
     $f->setOrder(new ARExpressionHandle('NewsPost.ID'), 'DESC');
     $newspost = ActiveRecordModel::getRecordSetArray('NewsPost', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($emptyListIsException && count($newspost) == 0) {
         throw new Exception('News post not found');
     }
     while ($category = array_shift($newspost)) {
         $xmlNewsPost = $response->addChild('newspost');
         foreach ($category as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xmlNewsPost->addChild($k, htmlentities($v));
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 3
0
 public function filter($emptyListIsException = false)
 {
     $request = $this->application->getRequest();
     $parser = $this->getParser();
     $apiFieldNames = $parser->getApiFieldNames();
     $parser->loadDataInRequest($request);
     $f = new ARSelectFilter();
     $ID = $request->get('ID');
     if (!empty($countryID)) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('DeliveryZoneCountry', 'ID'), $ID));
     }
     $countryZones = ActiveRecordModel::getRecordSetArray('DeliveryZoneCountry', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($emptyListIsException && count($countryZones) == 0) {
         throw new Exception('DeliveryZoneCountry not found');
     }
     while ($country_zone = array_shift($countryZones)) {
         $xmlCountryZone = $response->addChild('delivery_zone_country');
         foreach ($country_zone as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xmlCountryZone->addChild($k, $v);
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 4
0
 public function filter($emptyListIsException = false)
 {
     $request = $this->application->getRequest();
     $parser = $this->getParser();
     $apiFieldNames = $parser->getApiFieldNames();
     $parser->loadDataInRequest($request);
     $f = new ARSelectFilter();
     $id = $request->get('ID');
     if (intval($id) > 0) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('BillingAddress', 'ID'), $id));
     } else {
         throw new Exception('Billing Address ID is required');
     }
     //$f->setOrder(MultiLingualObject::getLangOrderHandle(new ARFieldHandle('Category', 'name')));
     $shipping_address = ActiveRecordModel::getRecordSetArray('BillingAddress', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($emptyListIsException && count($shipping_address) == 0) {
         throw new Exception('BillingAddress not found');
     }
     while ($category = array_shift($shipping_address)) {
         $xmlNewsPost = $response->addChild('billing_address');
         foreach ($category as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xmlNewsPost->addChild($k, htmlentities($v));
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 5
0
 public function add_to_cart()
 {
     $request = $this->application->getRequest();
     $productID = $request->get('productID');
     $customerOrderID = $request->get('customerOrderID');
     $count = $request->get('count');
     if (!isset($customerOrderID) && intval($customerOrderID == 0)) {
         throw new Exception('Order ID is required');
     }
     $order = CustomerOrder::getInstanceById($customerOrderID);
     $order->load(true);
     $order->loadAll();
     //throw new Exception('order : ' . $order->getTotal(true));
     $product = Product::getInstanceByID($productID, true, true);
     $product->load(true);
     //$variations = !$product->parent->get() ? $product->getVariationData($this->application) : array('1','2');
     //throw new Exception('variation ' . json_encode($variations) . ' parent : ' . $product->getID() . ' productID ' . $productID);
     if (!$product->isAvailable()) {
         throw new Exception('Product ' . $productID . ' is not Available ');
     } else {
         if ($count < $product->getMinimumQuantity()) {
             $count = $product->getMinimumQuantity();
         }
         ActiveRecordModel::beginTransaction();
         $item = $order->addProduct($product, $count);
         if ($item instanceof OrderedItem) {
             if ($order->isMultiAddress->get()) {
                 $item->save();
             }
         }
         if ($product->parent->get()) {
             $order->mergeItems();
         } else {
             $item->save();
         }
         //$order->mergeItems();
         $order->getTotal(true);
         $order->totalAmount->set($order->getTotal(true));
         $order->getTaxAmount();
         $order->save(true);
         ActiveRecordModel::commit();
     }
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($item->getID() > 0) {
         $parser = $this->getParser();
         $apiFieldNames = $parser->getApiFieldNames();
         $selFilter = new ARSelectFilter();
         $selFilter->mergeCondition(new EqualsCond(new ARFieldHandle('OrderedItem', 'ID'), $item->getID()));
         $orderedItem = OrderedItem::getRecordSetArray('OrderedItem', $selFilter);
         while ($item = array_shift($orderedItem)) {
             $orderedItemXml = $response->addChild('ordered_item');
             foreach ($item as $k => $v) {
                 if (in_array($k, $apiFieldNames)) {
                     $orderedItemXml->addChild($k, htmlentities($v));
                 }
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 6
0
 public function filter($emptyListIsException = false)
 {
     $request = $this->application->getRequest();
     $parser = $this->getParser();
     $apiFieldNames = $parser->getApiFieldNames();
     $parser->loadDataInRequest($request);
     $f = new ARSelectFilter();
     $orderID = $request->get('orderID');
     if (intval($orderID) > 0) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('Shipment', 'orderID'), $orderID));
     } else {
         throw new Exception("Order ID is required");
     }
     $shipment = ActiveRecordModel::getRecordSetArray('Shipment', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($emptyListIsException && count($shipment) == 0) {
         throw new Exception('Shipment not found');
     }
     while ($ser = array_shift($shipment)) {
         $xmlShipment = $response->addChild('shipment');
         foreach ($ser as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xmlShipment->addChild($k, $v);
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 7
0
 public function filter()
 {
     $parser = $this->getParser();
     $request = $this->getApplication()->getRequest();
     $name = $request->get('name');
     $request->set('name', '%' . serialize($name) . '%');
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     $products = Product::getRecordSetArray('Product', $parser->getARSelectFilter(), array('Category', 'Manufacturer', 'ProductImage'));
     // $fieldNames = $parser->getApiFieldNames();
     foreach ($products as $product) {
         $this->fillResponseItem($response->addChild('product'), $product);
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 8
0
 public function filter($emptyListIsException = false)
 {
     $request = $this->application->getRequest();
     $parser = $this->getParser();
     $parser->loadDataInRequest($request);
     $countries = Country::getNewInstance()->getCountryList($this->application);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     foreach ($countries as $k => $v) {
         $xmlState = $response->addChild('country');
         $xmlState->addChild("countryID", htmlentities($k));
         $xmlState->addChild("country_name", $v);
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 9
0
 public function filter($emptyListIsException = false)
 {
     $request = $this->application->getRequest();
     $parser = $this->getParser();
     $apiFieldNames = $parser->getApiFieldNames();
     $parser->loadDataInRequest($request);
     $f = $parser->getARSelectFilter();
     $f->setOrder(new ARExpressionHandle('ProductOption.position'), 'ASC');
     $productOptions = ActiveRecordModel::getRecordSetArray('ProductOption', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($emptyListIsException && count($productOptions) == 0) {
         throw new Exception('Product option not found');
     }
     while ($option = array_shift($productOptions)) {
         $xml = $response->addChild('product_option');
         foreach ($option as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xml->addChild($k, $v);
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 10
0
 public function add_coupon()
 {
     $request = $this->application->getRequest();
     $code = $request->get('couponCode');
     $orderID = $request->get('orderID');
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if (strlen($code)) {
         $order = CustomerOrder::getInstanceByID($orderID, CustomerOrder::LOAD_DATA);
         $condition = DiscountCondition::getInstanceByCoupon($code);
         if ($condition) {
             if (!$order->hasCoupon($code)) {
                 $coupon = OrderCoupon::getNewInstance($order, $code);
                 $coupon->save();
                 $order->getCoupons(true);
                 if ($order->hasCoupon($code)) {
                     $order->loadAll();
                     $order->getTotal(true);
                     $order->totalAmount->set($order->getTotal(true));
                     $order->getTaxAmount();
                     $order->save();
                     $response->addChild('message', 'Coupon ' . $code . ' was successfully added');
                 } else {
                     throw new Exception("Cant add coupon " . $code);
                 }
             } else {
                 throw new Exception("The coupon " . $code . " already added");
             }
         } else {
             throw new Exception("Cant add coupon " . $code);
         }
         $order->getCoupons(true);
     } else {
         throw new Exception("Incorrect coupon code" . $code);
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 11
0
 function send()
 {
     $parser = $this->getParser();
     $request = $this->application->getRequest();
     $apiFieldNames = $parser->getApiFieldNames();
     $orderID = $request->get('orderID');
     $comment = $request->get('text');
     if (!isset($orderID)) {
         throw new Exception("Order ID is required");
     }
     if (!isset($comment)) {
         throw new Exception("User comment is required");
     }
     $order = CustomerOrder::getInstanceById($orderID, CustomerOrder::LOAD_DATA);
     $order->user->get()->load();
     $note = OrderNote::getNewInstance($order, $order->user->get());
     $note->isAdmin->set(false);
     $note->text->set($comment);
     $note->save();
     $note->load(true);
     /*if ($this->application->config->get('NOTIFY_NEW_NOTE'))
             {
                 $order->user->get()->load();
     
                 $email = new Email($this->application);
                 $email->setTo($this->application->config->get('NOTIFICATION_EMAIL'), $this->application->config->get('STORE_NAME'));
                 $email->setTemplate('notify.message');
                 $email->set('order', $order->toArray(array('payments' => true)));
                 $email->set('message', $note->toArray());
                 $email->set('user', $order->user->toArray());
                 $email->send();
             }*/
     $f = new ARSelectFilter();
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderNote', 'ID'), $note->getID()));
     $orderNotes = ActiveRecordModel::getRecordSetArray('OrderNote', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     while ($notes = array_shift($orderNotes)) {
         $xmlPage = $response->addChild('note');
         foreach ($notes as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xmlPage->addChild($k, htmlentities($v));
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 12
0
 private function apiActionGetOrdersBySelectFilter($ARSelectFilter, $allowEmptyResponse = false)
 {
     set_time_limit(0);
     $ARSelectFilter->setOrder(new ARExpressionHandle('CustomerOrder.ID'), 'DESC');
     $customerOrders = ActiveRecordModel::getRecordSet('CustomerOrder', $ARSelectFilter, array('User'));
     if ($allowEmptyResponse == false && count($customerOrders) == 0) {
         throw new Exception('Order not found');
     }
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     foreach ($customerOrders as $order) {
         $order->loadAll();
         $transactions = $order->getTransactions();
         $this->fillResponseItem($response->addChild('order'), $order->toArray());
         unset($order);
         ActiveRecord::clearPool();
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 13
0
 public function getAuthCredentials(Request $request)
 {
     $xml = $request->get(ApiReader::API_PARSER_DATA);
     if ($xml != null) {
         $auth = array_shift($xml->xpath($this->getXMLPath() . '/auth'));
         if (count($auth) > 0) {
             return LiveCartSimpleXMLElement::Xml2SimpleArray($auth);
         }
     }
 }
Exemplo n.º 14
0
 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 ');
             }*/
 }
Exemplo n.º 15
0
 public function filter()
 {
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     $parser = $this->getParser();
     $customers = User::getRecordSetArray('User', $parser->getARSelectFilter(), true);
     // $addressFieldNames = array_keys(ActiveRecordModel::getSchemaInstance('UserAddress')->getFieldList());
     $addressFieldNames = array('firstName', 'lastName', 'address1', 'address2', 'city', 'stateName', 'postalCode', 'phone');
     $userFieldNames = $parser->getApiFieldNames();
     foreach ($customers as $customer) {
         $customerNode = $response->addChild('customer');
         foreach ($userFieldNames as $fieldName) {
             $customerNode->addChild($fieldName, is_string($customer[$fieldName]) ? $customer[$fieldName] : '');
         }
         // todo: join? how?? m?!
         $u = User::getInstanceByID($customer['ID'], true);
         $u->loadAddresses();
         // default billing and shipping addreses
         foreach (array('defaultShippingAddress', 'defaultBillingAddress') as $addressType) {
             if (is_numeric($customer[$addressType . 'ID'])) {
                 $address = $u->defaultBillingAddress->get()->userAddressID->get();
                 foreach ($addressFieldNames as $addressFieldName) {
                     $customerNode->addChild($addressType . '_' . $addressFieldName, $address->{$addressFieldName}->get());
                 }
             }
         }
         $this->mergeUserEavFields($customerNode, $u);
         $this->clear($u);
     }
     return new SimpleXMLResponse($response);
 }
Exemplo n.º 16
0
 public function az()
 {
     $parser = $this->getParser();
     $request = $this->getApplication()->getRequest();
     $name = $request->get('name');
     $request->set('name', '%' . serialize($name) . '%');
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     $selFilter = $parser->getARSelectFilter();
     $selFilter->mergeCondition(new EqualsCond(new ARFieldHandle('Product', 'categoryID'), $request->get('categoryID')));
     $selFilter->setOrder(new ARExpressionHandle('Product.name'), 'ASC');
     $isEnabled = $request->get('isEnabled');
     if (isset($isEnabled)) {
         $selFilter->mergeCondition(new EqualsCond(new ARFieldHandle('Product', 'isEnabled'), $isEnabled));
     }
     $products = ActiveRecordModel::getRecordSetArray('Product', $selFilter, array('Category', 'Manufacturer', 'ProductImage'));
     foreach ($products as $product) {
         $this->fillResponseItem($response->addChild('product'), $product);
     }
     return new SimpleXMLResponse($response);
 }