Beispiel #1
0
 public function categories()
 {
     // get store categories
     $selected = array();
     foreach ($this->getStore()->getRelatedRecordSetArray('ClonedStoreCategory', select()) as $cat) {
         $selected[$cat['categoryID']] = true;
     }
     // load tree
     $rootID = 1;
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('Category', 'isEnabled'), true));
     $categories = ActiveRecordModel::getRecordSetArray('Category', Category::getInstanceByID($rootID, true)->getBranchFilter($f));
     $index = array($rootID => array('children' => array(), 'key' => 1, 'title' => 'Root', 'expand' => true));
     foreach ($categories as $key => $category) {
         $cat = array('key' => $category['ID'], 'title' => $category['name_lang']);
         if (isset($selected[$category['ID']]) || !empty($index[$category['parentNodeID']]['select'])) {
             $cat['select'] = true;
         }
         $index[$category['ID']] = $cat;
         $index[$category['parentNodeID']]['children'][] =& $index[$category['ID']];
     }
     $response = new ActionResponse();
     $response->set('tree', json_encode(array($index[1])));
     $response->set('store', $this->getStore()->toArray());
     return $response;
 }
Beispiel #2
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);
 }
Beispiel #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 (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);
 }
Beispiel #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 (!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);
 }
Beispiel #5
0
 public function getTopCustomers()
 {
     $this->setDateHandle(new ARFieldHandle('CustomerOrder', 'dateCompleted'));
     $this->setChartType(self::TABLE);
     $q = $this->getQuery('ROUND(SUM(CustomerOrder.totalAmount * ' . $this->getCurrencyMultiplier() . '), 2)');
     $f = $q->getFilter();
     $f->resetOrder();
     $f->resetGrouping();
     $f->setOrder(new ARExpressionHandle('cnt'), 'DESC');
     $q->addField('userID');
     $f->setGrouping(new ARExpressionHandle('userID'));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), 1));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isCancelled'), 0));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isPaid'), 1));
     $f->setLimit(self::TABLE_LIMIT);
     $q->joinTable('CustomerOrder', 'User', 'userID', 'ID');
     $this->getReportData($q);
     $ids = array();
     foreach ($this->values as $product) {
         $ids[$product['userID']] = $product['cnt'];
     }
     // fetch user details
     $fields = array_flip(array('fullName', 'cnt'));
     foreach (ActiveRecordModel::getRecordSetArray('User', new ARSelectFilter(new INCond(new ARFieldHandle('User', 'ID'), array_keys($ids)))) as $user) {
         $user['cnt'] = $ids[$user['ID']];
         $ids[$user['ID']] = array_merge($fields, array_intersect_key($user, $fields));
     }
     $this->values = $ids;
 }
Beispiel #6
0
 public function index()
 {
     // get filter to select manufacturers of active products only
     $rootCat = Category::getRootNode();
     $f = new ARSelectFilter();
     $productFilter = new ProductFilter($rootCat, $f);
     $ids = $counts = array();
     foreach (ActiveRecordModel::getDataBySQL('SELECT DISTINCT(manufacturerID), COUNT(*) AS cnt FROM Product ' . $f->createString() . ' GROUP BY manufacturerID') as $row) {
         $ids[] = $row['manufacturerID'];
         $counts[$row['manufacturerID']] = $row['cnt'];
     }
     $f = new ARSelectFilter(new InCond(new ARFieldHandle('Manufacturer', 'ID'), $ids));
     $f->mergeCondition(new NotEqualsCond(new ARFieldHandle('Manufacturer', 'name'), ''));
     $f->setOrder(new ARFieldHandle('Manufacturer', 'name'));
     $manufacturers = ActiveRecordModel::getRecordSetArray('Manufacturer', $f);
     foreach ($manufacturers as &$manufacturer) {
         $manufacturer['url'] = $this->getManufacturerFilterUrl($manufacturer);
     }
     $this->addBreadCrumb($this->translate('_manufacturers'), '');
     $response = new ActionResponse();
     $response->setReference('manufacturers', $manufacturers);
     $response->set('counts', $counts);
     $response->set('rootCat', $rootCat->toArray());
     return $response;
 }
Beispiel #7
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);
 }
 /**
  *	Main settings page
  */
 public function index()
 {
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle('StaticPage', 'position'));
     $f->setOrder(new ARFieldHandle('StaticPage', 'parentID'));
     $s = ActiveRecordModel::getRecordSetArray('StaticPage', $f);
     $pages = array();
     foreach ($s as $page) {
         $pointers[$page['ID']] = array('title' => $page['title_lang'], 'id' => $page['ID'], 'parentID' => $page['parentID']);
     }
     foreach ($pointers as $page) {
         if ($page['parentID'] && !empty($pointers[$page['parentID']])) {
             $root =& $pointers[$page['parentID']];
         } else {
             $root =& $pages;
         }
         $root['children'][] =& $pointers[$page['id']];
     }
     $response = new ActionResponse();
     $response->set('pages', json_encode($pages));
     $form = $this->getForm();
     $page = StaticPage::getNewInstance();
     $page->getSpecification()->setFormResponse($response, $form);
     $response->set('form', $form);
     $response->set('page', $page->toArray());
     return $response;
 }
Beispiel #9
0
 public function testAutoReference()
 {
     $child = ActiveRecordModel::getNewInstance('AutoReferenceChild');
     $child->name->set('child');
     $child->save();
     $parent = ActiveRecordModel::getNewInstance('AutoReferenceParent');
     $parent->setID(4);
     $parent->name->set('parent');
     $parent->reference->set($child);
     $parent->save();
     ActiveRecordModel::clearPool();
     // test loading data array
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('AutoReferenceParent', 'ID'), 4));
     $array = array_shift(ActiveRecordModel::getRecordSetArray('AutoReferenceParent', $f));
     $this->assertEqual($array['ID'], 4);
     $this->assertEqual($array['Reference']['name'], 'child');
     ActiveRecordModel::clearPool();
     // test loading instance by ID
     $newParent = ActiveRecordModel::getInstanceByID('AutoReferenceParent', 4, ActiveRecordModel::LOAD_DATA);
     $this->assertEqual($newParent->reference->get()->name->get(), 'child');
     $this->assertNotSame($parent, $newParent);
     $this->assertNotSame($child, $newParent->reference->get());
     // test loading record set
     $newParent = ActiveRecordModel::getRecordSet('AutoReferenceParent', $f)->get(0);
     $this->assertEqual($newParent->reference->get()->name->get(), 'child');
     $this->assertNotSame($parent, $newParent);
     $this->assertNotSame($child, $newParent->reference->get());
 }
Beispiel #10
0
 public function process()
 {
     if (!$this->response instanceof ActionResponse) {
         return;
     }
     $products = $this->response->get('products');
     $ids = array();
     foreach ($products as $key => $product) {
         $ids[$product['ID']] = !empty($product['parentID']) ? $product['parentID'] : $product['ID'];
     }
     if (!$ids) {
         return;
     }
     $f = select(in(f('ProductImage.productID'), array_values($ids)), new LikeCond(f('ProductImage.title'), '%Virtual Mirror%'));
     $hasMirror = array();
     foreach (ActiveRecordModel::getRecordSetArray('ProductImage', $f) as $mirror) {
         $hasMirror[$mirror['productID']] = true;
     }
     foreach ($ids as $realID => $parentID) {
         if (!empty($hasMirror[$parentID])) {
             $hasMirror[$realID] = true;
         }
     }
     foreach ($products as $key => $product) {
         if ($hasMirror[$product['ID']]) {
             $products[$key]['hasMirror'] = true;
         }
     }
     $this->response->set('hasMirror', $hasMirror);
     $this->response->set('products', $products);
 }
Beispiel #11
0
 public function index()
 {
     $this->addIndexBreadCrumb();
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('NewsPost', 'isEnabled'), true));
     $f->setOrder(new ARFieldHandle('NewsPost', 'position'), 'DESC');
     return new ActionResponse('news', ActiveRecordModel::getRecordSetArray('NewsPost', $f));
 }
Beispiel #12
0
 public function testEavQueue()
 {
     // set up Manufacturer records
     $field = EavField::getNewInstance('Manufacturer', EavField::DATATYPE_TEXT, EavField::TYPE_TEXT_SIMPLE);
     $field->save();
     $data = array('first', 'second', 'third');
     foreach ($data as $value) {
         $manufacturer = Manufacturer::getNewInstance($value);
         $manufacturer->getSpecification()->setAttributeValueByLang($field, 'en', $value . ' test');
         $manufacturer->save();
     }
     ActiveRecordModel::clearPool();
     // fetch them from database
     $manufacturers = ActiveRecordModel::getRecordSetArray('Manufacturer', new ARSelectFilter());
     foreach ($manufacturers as &$entry) {
         ActiveRecordModel::addToEavQueue('Manufacturer', $entry);
     }
     // duplicate
     $manufacturers = array_merge($manufacturers, $manufacturers);
     // load EAV data
     ActiveRecordModel::loadEav();
     foreach ($manufacturers as $man) {
         $this->assertEqual($man['name'] . ' test', $man['attributes'][$field->getID()]['value_en']);
     }
 }
Beispiel #13
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);
 }
Beispiel #14
0
 /**
  *	@role login
  */
 public function index()
 {
     $this->addAccountBreadcrumb();
     // get recent orders
     $f = new ARSelectFilter();
     $f->setLimit($this->config->get('USER_COUNT_RECENT_ORDERS'));
     $orders = $this->loadOrders($f);
     $orderArray = $this->getOrderArray($orders);
     // get downloadable items
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $this->user->getID()));
     $f->setLimit(self::COUNT_RECENT_FILES);
     $response = new ActionResponse();
     $response->set('orders', $orderArray);
     $response->set('files', $this->loadDownloadableItems(new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $this->user->getID()))));
     // get unread messages
     ClassLoader::import('application.model.order.OrderNote');
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('OrderNote', 'userID'), $this->user->getID()));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderNote', 'isAdmin'), 1));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderNote', 'isRead'), 0));
     $f->setOrder(new ARFieldHandle('OrderNote', 'ID'), 'DESC');
     $response->set('notes', ActiveRecordModel::getRecordSetArray('OrderNote', $f, array('User')));
     // feedback/confirmation message that was stored in session by some other action
     $response->set('userConfirm', $this->session->pullValue('userConfirm'));
     return $response;
 }
Beispiel #15
0
 public function index()
 {
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle('NewsPost', 'position'), 'DESC');
     $response = new ActionResponse('newsList', ActiveRecordModel::getRecordSetArray('NewsPost', $f));
     $response->set('form', $this->buildForm());
     return $response;
 }
Beispiel #16
0
 private function fetchData(SearchableModel $searchable, ARSelectFilter $filter)
 {
     $class = $searchable->getClassName();
     $ret = array();
     $ret['records'] = ActiveRecordModel::getRecordSetArray($class, $filter);
     $ret['count'] = ActiveRecordModel::getRecordCount($class, $filter);
     $ret['meta'] = $searchable->toArray();
     return $ret;
 }
Beispiel #17
0
 private function loadDefaultImage()
 {
     if (!isset($this->object['DefaultImage']) && isset($this->object['defaultImageID'])) {
         $defaultImageArray = ActiveRecordModel::getRecordSetArray('ProductImage', select(eq(f('ProductImage.ID'), $this->object['defaultImageID'])));
         if (count($defaultImageArray) > 0) {
             $this->object['DefaultImage'] = array_merge(current($defaultImageArray), array('Product' => ActiveRecord::getArrayData('Product-' . $this->object['ID'])));
         }
     }
 }
Beispiel #18
0
 protected function postProcessData()
 {
     $addresses = array();
     foreach ($this->data as $key => $shipment) {
         $id = !empty($shipment['shippingAddressID']) ? $shipment['shippingAddressID'] : $shipment['CustomerOrder']['shippingAddressID'];
         $addresses[$id] = $key;
     }
     foreach (ActiveRecordModel::getRecordSetArray('UserAddress', select(in('UserAddress.ID', array_keys($addresses)))) as $address) {
         $this->data[$addresses[$address['ID']]]['ShippingAddress'] = $address;
     }
 }
Beispiel #19
0
 public function news()
 {
     $this->shouldBeEnabledFeed('NEWS_POSTS');
     $this->setLayout('empty');
     $response = new XMLResponse();
     $f = select(eq(f('NewsPost.isEnabled'), true));
     $f->setLimit($this->config->get('NUMBER_OF_NEWS_POSTS_TO_INCLUDE'));
     $f->setOrder(f('NewsPost.position'), ARSelectFilter::ORDER_DESC);
     $response->set('feed', ActiveRecordModel::getRecordSetArray('NewsPost', $f));
     $this->application->getLocale()->translationManager()->loadFile('News');
     return $response;
 }
Beispiel #20
0
 public function process()
 {
     $this->application->getRouter()->removeAutoAppendVariable('currency');
     if (!$this->response instanceof ActionResponse) {
         return;
     }
     $products = $this->response->get('products');
     $parents = $variations = array();
     foreach ($products as $key => $product) {
         if ($product['parentID']) {
             $parents[$product['parentID']] = true;
             $variations[$key] = $product;
         }
     }
     if (!$parents) {
         return;
     }
     $loadedParents = array();
     foreach (ActiveRecordModel::getRecordSetArray('Product', select(in(f('Product.ID'), array_keys($parents))), array('Manufacturer', 'DefaultImage' => 'ProductImage', 'Category')) as $parent) {
         $loadedParents[$parent['ID']] = $parent;
     }
     ProductSpecification::loadSpecificationForRecordSetArray($loadedParents);
     ProductPrice::loadPricesForRecordSetArray($loadedParents);
     foreach ($products as $key => $product) {
         if ($product['parentID']) {
             $parent = $loadedParents[$product['parentID']];
             foreach ($parent as $field => $value) {
                 if (empty($product[$field])) {
                     $product[$field] = $parent[$field];
                 }
             }
             foreach (array('price_USD', 'price_CAD', 'formattedPrice', 'formattedListPrice') as $field) {
                 if (isset($parent[$field])) {
                     $product[$field] = $parent[$field];
                 }
             }
             ///var_dump($parent);exit;
             $products[$key] = $product;
         }
     }
     ProductSet::loadVariationsForProductArray($variations);
     foreach ($variations as $key => $variation) {
         $vars = array();
         foreach ($variation['variationTypes'] as $type) {
             $vars[] = $type['name_lang'];
         }
         if ($vars) {
             $products[$key]['name_lang'] .= ' (' . implode(' / ', $vars) . ')';
         }
     }
     $this->response->set('products', $products);
 }
Beispiel #21
0
 /**
  *	Main settings page
  */
 public function index()
 {
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle('StaticPage', 'position'));
     $s = ActiveRecordModel::getRecordSetArray('StaticPage', $f);
     $pages = array();
     foreach ($s as $page) {
         $pages[$page['ID']] = array('title' => $page['title_lang'], 'parent' => $page['parentID']);
     }
     $response = new ActionResponse();
     $response->set('pages', json_encode($pages));
     return $response;
 }
 public function index()
 {
     $owner = ActiveRecordModel::getInstanceByID($this->getOwnerClass(), (int) $this->request->get('id'));
     $filter = new ARSelectFilter();
     $filter->setCondition(new EqualsCond(new ARFieldHandle($this->getModelClass(), $this->getForeignKeyName()), $owner->getID()));
     $filter->setOrder(new ARFieldHandle($this->getModelClass(), 'position'));
     $imageArray = ActiveRecordModel::getRecordSetArray($this->getModelClass(), $filter);
     $response = new ActionResponse();
     $response->set('form', $this->buildForm($owner->getID()));
     $response->set('maxSize', ini_get('upload_max_filesize'));
     $response->set('ownerId', $owner->getID());
     $response->set('images', json_encode($imageArray));
     return $response;
 }
Beispiel #23
0
 public function index()
 {
     ClassLoader::import('application.controller.CategoryController');
     $this->request->set('id', Category::ROOT_ID);
     $this->request->set('cathandle', '-');
     $response = parent::index();
     // load site news
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('NewsPost', 'isEnabled'), true));
     $f->setOrder(new ARFieldHandle('NewsPost', 'position'), 'DESC');
     $f->setLimit($this->config->get('NUM_NEWS_INDEX') + 1);
     $news = ActiveRecordModel::getRecordSetArray('NewsPost', $f);
     $response->set('news', $news);
     $response->set('isNewsArchive', count($news) > $this->config->get('NUM_NEWS_INDEX'));
     return $response;
 }
Beispiel #24
0
 public function get()
 {
     $request = $this->application->getRequest();
     $products = ActiveRecordModel::getRecordSetArray('Product', select(eq(f('Product.sku'), $request->get('SKU'))), array('Category', 'Manufacturer', 'ProductImage'));
     if (count($products) == 0) {
         throw new Exception('Product not found');
     }
     // --
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     $responseProduct = $response->addChild('product');
     while ($product = array_shift($products)) {
         $this->fillResponseItem($responseProduct, $product);
     }
     return new SimpleXMLResponse($response);
 }
Beispiel #25
0
 public static function getStateIDByName($countryCode, $name)
 {
     $f = new ARSelectFilter();
     $f->setCondition(new EqualsCond(new ARFieldHandle('State', 'countryID'), $countryCode));
     $nameCond = new EqualsCond(new ARFieldHandle('State', 'name'), $name);
     $nameCond->addOr(new EqualsCond(new ARFieldHandle('State', 'code'), $name));
     $f->mergeCondition($nameCond);
     $f->setOrder(new ARFieldHandle('State', 'name'));
     $f->setLimit(1);
     $stateArray = ActiveRecordModel::getRecordSetArray('State', $f);
     if ($stateArray) {
         return $stateArray[0]['ID'];
     } else {
         return null;
     }
 }
Beispiel #26
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);
 }
 /**
  * @role update
  */
 public function upload()
 {
     $result = parent::upload();
     $request = $this->getRequest();
     if ($request->get('setAsMainImage')) {
         $data = json_decode($result->get('result'));
         $imageID = $data->ID;
         $filter = select(eq(f('ProductImage.productID'), $request->get('ownerId')));
         $filter->setOrder(f('ProductImage.position'));
         $r = ActiveRecordModel::getRecordSetArray('ProductImage', $filter, true);
         $order = array($imageID);
         foreach ($r as $item) {
             if ($imageID != $item['ID']) {
                 $order[] = $item['ID'];
             }
         }
         parent::saveOrder($order);
     }
     return $result;
 }
Beispiel #28
0
 private function fetchData(SearchableModel $searchable, ARSelectFilter $filter)
 {
     $class = $searchable->getClassName();
     $ret = array();
     $ret['records'] = ActiveRecordModel::getRecordSetArray($class, $filter, true);
     $ret['count'] = ActiveRecordModel::getRecordCount($class, $filter);
     // calculate form and to
     $ret['from'] = $filter->getOffset();
     $ret['to'] = $filter->getLimit() + $ret['from'];
     $diff = $ret['to'] - $ret['from'];
     $c = count($ret['records']);
     if ($diff != $c) {
         $ret['to'] = $ret['from'] + $c;
     }
     $ret['from']++;
     $ret['meta'] = $searchable->toArray();
     if (method_exists($this, 'toArray_' . $searchable->getClassName())) {
         call_user_func_array(array($this, 'toArray_' . $searchable->getClassName()), array(&$ret['records']));
     }
     return $ret;
 }
Beispiel #29
0
 private function getBestsellerData($sql, $order = 'DESC')
 {
     $this->setChartType(self::TABLE);
     $q = $this->getQuery($sql);
     $f = $q->getFilter();
     $f->resetOrder();
     $f->resetGrouping();
     $f->setOrder(new ARExpressionHandle('cnt'), $order);
     $q->addField('OrderedItem.productID');
     $f->setGrouping(new ARExpressionHandle('OrderedItem.productID'));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), 1));
     $f->setLimit(self::TABLE_LIMIT);
     $q->joinTable('CustomerOrder', 'OrderedItem', 'ID', 'customerOrderID');
     $this->getReportData($q);
     $ids = array();
     foreach ($this->values as $product) {
         $ids[$product['productID']] = $product['cnt'];
     }
     // fetch product details
     $fields = array_flip(array('sku', 'name', 'cnt'));
     $products = ActiveRecordModel::getRecordSetArray('Product', new ARSelectFilter(new INCond(new ARFieldHandle('Product', 'ID'), array_keys($ids))), array('Parent'));
     ProductSet::loadVariationsForProductArray($products);
     foreach ($products as $product) {
         $product['cnt'] = $ids[$product['ID']];
         if (empty($product['name'])) {
             if (!empty($product['parentID'])) {
                 $parent = Product::getInstanceByID($product['parentID'], true);
                 $product['name'] = $parent->getValueByLang('name');
             } else {
                 $product['name'] = '';
             }
         }
         if (isset($product['variationValues'])) {
             $product['name'] .= ' (' . implode(' / ', $product['variationValues']) . ')';
         }
         // array_merge to put all array values in the same order
         $ids[$product['ID']] = array_merge($fields, array_intersect_key($product, $fields));
     }
     $this->values = $ids;
 }
Beispiel #30
0
 public function filter($emptyListIsException = false)
 {
     $request = $this->application->getRequest();
     $parser = $this->getParser();
     $apiFieldNames = $parser->getApiFieldNames();
     $parser->loadDataInRequest($request);
     $f = $parser->getARSelectFilter();
     $orderedItemOptions = ActiveRecordModel::getRecordSetArray('OrderedItemOption', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($emptyListIsException && count($orderedItemOptions) == 0) {
         throw new Exception('Ordered Item Option not found');
     }
     while ($option = array_shift($orderedItemOptions)) {
         $xml = $response->addChild('option');
         foreach ($option as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xml->addChild($k, $v);
             }
         }
     }
     return new SimpleXMLResponse($response);
 }