Example #1
0
 public static function getOrderFiles(ARSelectFilter $f)
 {
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isCancelled'), 0));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isPaid'), true));
     //$f->mergeCondition(new EqualsCond(new ARFieldHandle('Product', 'type'), Product::TYPE_DOWNLOADABLE));
     $f->setOrder(new ARFieldHandle('CustomerOrder', 'ID'), 'DESC');
     $downloadable = ActiveRecordModel::getRecordSet('OrderedItem', $f, array('Product', 'CustomerOrder'));
     $fileArray = array();
     foreach ($downloadable as &$item) {
         $files = $item->getProduct()->getFiles();
         $itemFiles = array();
         foreach ($files as $file) {
             if ($item->isDownloadable($file)) {
                 $itemFiles[] = $file->toArray();
             }
         }
         if (!$itemFiles) {
             continue;
         }
         $array = $item->toArray();
         $array['Product']['Files'] = ProductFileGroup::mergeGroupsWithFields($item->getProduct()->getFileGroups()->toArray(), $itemFiles);
         foreach ($array['Product']['Files'] as $key => $file) {
             if (!isset($file['ID'])) {
                 unset($array['Product']['Files'][$key]);
             }
         }
         $fileArray[] = $array;
     }
     return $fileArray;
 }
Example #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');
     $shippingServiceID = $request->get('shippingServiceID');
     if (intval($ID) > 0) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('ShippingRate', 'ID'), $ID));
     }
     if (intval($shippingServiceID) > 0) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('ShippingRate', 'shippingServiceID'), $shippingServiceID));
     }
     $shipping_rate = ActiveRecordModel::getRecordSetArray('ShippingRate', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($emptyListIsException && count($shipping_rate) == 0) {
         throw new Exception('ShippingService not found');
     }
     while ($rate = array_shift($shipping_rate)) {
         $xmlRate = $response->addChild('shipping_rate');
         foreach ($rate as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xmlRate->addChild($k, $v);
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Example #3
0
 /**
  * Get related product active record by ID
  *
  * @param mixed $recordID
  * @param bool $loadRecordData
  * @param bool $loadReferencedRecords
  *
  * @return ProductRelationshipGroup
  */
 public static function getInstance(Product $product, Product $relatedProduct, $type, $loadRecordData = false, $loadReferencedRecords = false)
 {
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle(__CLASS__, 'productID'), $product->getID()));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'relatedProductID'), $relatedProduct->getID()));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'type'), $type));
     $set = parent::getRecordSet(__CLASS__, $f, $loadReferencedRecords);
     return $set->size() ? $set->get(0) : null;
 }
Example #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($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);
 }
Example #5
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;
 }
Example #6
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');
     $parentNodeID = $request->get('parentNodeID');
     if (intval($id) > 0) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('Category', 'ID'), $id));
     }
     if (intval($parentNodeID) > 0) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('Category', 'parentNodeID'), $parentNodeID));
     }
     $f->setOrder(MultiLingualObject::getLangOrderHandle(new ARFieldHandle('Category', 'name')));
     $categories = ActiveRecordModel::getRecordSetArray('Category', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($emptyListIsException && count($categories) == 0) {
         throw new Exception('Category not found');
     }
     while ($category = array_shift($categories)) {
         $xmlCategory = $response->addChild('category');
         foreach ($category as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xmlCategory->addChild($k, htmlentities($v));
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Example #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);
 }
Example #8
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);
 }
Example #9
0
 public static function getUserToolbarItems($types = null, $filter = null, $order = 'ASC')
 {
     if ($filter == null) {
         $filter = new ARSelectFilter();
     }
     $filter->mergeCondition(eq(f(__CLASS__ . '.ownerID'), SessionUser::getUser()->getID()));
     $filter->setOrder(f(__CLASS__ . '.position'), $order);
     $m = array(BackendToolbarItem::TYPE_MENU => '', BackendToolbarItem::TYPE_PRODUCT => '', BackendToolbarItem::TYPE_USER => '', BackendToolbarItem::TYPE_ORDER => '');
     if (is_array($types) == false) {
         $types = array($types);
     }
     $conditions = array();
     foreach ($types as $type) {
         switch ($type) {
             case BackendToolbarItem::TYPE_MENU:
                 $conditions[] = isnotnull(f(__CLASS__ . '.menuID'));
                 break;
             case BackendToolbarItem::TYPE_PRODUCT:
                 $conditions[] = new AndChainCondition(array(isnotnull(f(__CLASS__ . '.productID')), isnotnull(f('Product.ID'))));
                 // fake inner join
                 break;
             case BackendToolbarItem::TYPE_USER:
                 $conditions[] = new AndChainCondition(array(isnotnull(f(__CLASS__ . '.userID')), isnotnull(f('User.ID'))));
                 break;
             case BackendToolbarItem::TYPE_ORDER:
                 $conditions[] = new AndChainCondition(array(isnotnull(f(__CLASS__ . '.orderID')), isnotnull(f('CustomerOrder.ID'))));
                 break;
         }
     }
     if (count($conditions)) {
         $filter->mergeCondition(new OrChainCondition($conditions));
     }
     return self::getRecordSetArray(__CLASS__, $filter, true);
 }
Example #10
0
 private static function getProductGroupsFilter(Product $product, $type)
 {
     $filter = new ARSelectFilter();
     $filter->setOrder(new ARFieldHandle("ProductRelationshipGroup", "position"), 'ASC');
     $filter->setCondition(new EqualsCond(new ARFieldHandle("ProductRelationshipGroup", "productID"), $product->getID()));
     $filter->mergeCondition(new EqualsCond(new ARFieldHandle("ProductRelationshipGroup", "type"), $type));
     return $filter;
 }
Example #11
0
 public static function getRecordCount($locale = null)
 {
     $filter = new ARSelectFilter();
     if ($locale) {
         $filter->mergeCondition(eq(f(__CLASS__ . '.locale'), $locale));
     }
     return ActiveRecordModel::getRecordCount(__CLASS__, $filter);
 }
Example #12
0
 public function getSpecificationFieldSet($loadReferencedRecords = false)
 {
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle($this->getFieldClass(), 'classID'), EavField::getClassID($this->owner)));
     if ($this->owner->getStringIdentifier()) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('EavField', 'stringIdentifier'), $this->owner->getStringIdentifier()));
     }
     $f->setOrder(new ARFieldHandle($this->getFieldClass(), 'position'));
     return ActiveRecordModel::getRecordSet($this->getFieldClass(), $f, $loadReferencedRecords);
 }
Example #13
0
 /**
  * Creates a select filter for fields groups
  * @return ARSelectFilter
  */
 private function getGroupFilter()
 {
     $filter = new ARSelectFilter(new EqualsCond(new ARFieldHandle('EavFieldGroup', 'classID'), $this->classID));
     if ($this->stringIdentifier) {
         $filter->mergeCondition(new EqualsCond(new ARFieldHandle('EavFieldGroup', 'stringIdentifier'), $this->stringIdentifier));
     }
     $filter->setOrder(new ARFieldHandle('EavFieldGroup', 'position'));
     return $filter;
 }
Example #14
0
 public static function getRecordSetByOrder(CustomerOrder $order, ARSelectFilter $filter = null, $loadReferencedRecords = false)
 {
     if (!$filter) {
         $filter = new ARSelectFilter();
     }
     $filter->mergeCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'orderID'), $order->getID()));
     $filter->setOrder(new ARFieldHandle(__CLASS__, 'time'), ARSelectFilter::ORDER_DESC);
     return self::getRecordSet($filter, $loadReferencedRecords);
 }
Example #15
0
 public function getUseCount()
 {
     $cond = $this->discountCondition->get();
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
     if ($cond->couponLimitType->get() == DiscountCondition::COUPON_LIMIT_USER && $this->order->get()->user->get()) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $this->order->get()->user->get()->getID()));
     }
     return $cond->getRelatedRecordCount(__CLASS__, $f, array('CustomerOrder'));
 }
Example #16
0
 public static function getUserAddress($className, $addressID, User $user)
 {
     $f = new ARSelectFilter();
     $f->setCondition(new EqualsCond(new ARFieldHandle($className, 'ID'), $addressID));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle($className, 'userID'), $user->getID()));
     $s = ActiveRecordModel::getRecordSet($className, $f, array('UserAddress'));
     if (!$s->size()) {
         throw new ARNotFoundException($className, $addressID);
     }
     return $s->get(0);
 }
Example #17
0
 protected function insert()
 {
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('SearchLog', 'keywords'), $this->keywords->get()));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('SearchLog', 'ip'), $this->ip->get()));
     if (!ActiveRecordModel::getRecordCount(__CLASS__, $f)) {
         parent::insert();
         $update = new ARUpdateFilter();
         $update->addModifier('time', new ARExpressionHandle('NOW()'));
         $update->setCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'ID'), $this->getID()));
         ActiveRecordModel::updateRecordSet(__CLASS__, $update);
     }
 }
Example #18
0
 /**
  * Get CustomerOrder instance from session
  *
  * @return CustomerOrder
  */
 public static function getOrder()
 {
     if (self::$instance) {
         return self::$instance;
     }
     $session = new Session();
     $id = $session->get('CustomerOrder');
     if ($id) {
         try {
             $instance = CustomerOrder::getInstanceById($id, true);
             if (!$instance->getOrderedItems()) {
                 $instance->loadItems();
             }
             $instance->isSyncedToSession = true;
         } catch (ARNotFoundException $e) {
             unset($instance);
         }
     }
     if (!isset($instance)) {
         $userId = SessionUser::getUser()->getID();
         // get the last unfinalized order by this user
         if ($userId > 0) {
             $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $userId));
             $f->mergeCondition(new NotEqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
             $f->setOrder(new ARFieldHandle('CustomerOrder', 'ID'), 'DESC');
             $f->setLimit(1);
             $orders = ActiveRecordModel::getRecordSet('CustomerOrder', $f);
             if ($orders->size()) {
                 $instance = $orders->get(0);
             }
         }
     }
     if (!isset($instance)) {
         $instance = CustomerOrder::getNewInstance(User::getNewInstance(0));
         $instance->user->set(NULL);
     }
     if (!$instance->user->get() && SessionUser::getUser()->getID() > 0) {
         $instance->setUser(SessionUser::getUser());
         $instance->save();
     }
     if ($instance->isFinalized->get()) {
         $session->unsetValue('CustomerOrder');
         return self::getOrder();
     }
     // fixes issue when trying to add OrderedItem to unsaved(without ID) CustomerOrder.
     // ~ but i don't know if returning unsaved CustomerOrder is expected behaviour.
     if ($instance->isExistingRecord() == false) {
         $instance->save(true);
     }
     self::setOrder($instance);
     return $instance;
 }
Example #19
0
 public static function getUserToolbarItems($types = null, $filter = null, $order = 'ASC')
 {
     if ($filter == null) {
         $filter = new ARSelectFilter();
     }
     $filter->mergeCondition(eq(f(__CLASS__ . '.ownerID'), SessionUser::getUser()->getID()));
     $filter->setOrder(f(__CLASS__ . '.position'), $order);
     $m = array(BackendToolbarItem::TYPE_MENU => 'menuID', BackendToolbarItem::TYPE_PRODUCT => 'productID', BackendToolbarItem::TYPE_USER => 'userID', BackendToolbarItem::TYPE_ORDER => 'orderID');
     if (is_array($types) == false) {
         $types = array($types);
     }
     $conditions = array();
     foreach ($types as $type) {
         if (array_key_exists($type, $m)) {
             $conditions[] = isnotnull(f(__CLASS__ . '.' . $m[$type]));
         }
     }
     if (count($conditions)) {
         $filter->mergeCondition(new OrChainCondition($conditions));
     }
     return self::getRecordSetArray(__CLASS__, $filter, true);
 }
Example #20
0
 public function view()
 {
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('NewsPost', 'ID'), $this->request->get('id')));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('NewsPost', 'isEnabled'), true));
     $s = ActiveRecordModel::getRecordSet('NewsPost', $f);
     if (!$s->size()) {
         throw new ARNotFoundException('NewsPost', $this->request->get('id'));
     }
     $newsPost = $s->get(0)->toArray();
     $this->addIndexBreadCrumb();
     $this->addBreadCrumb($newsPost['title_lang'], '');
     return new ActionResponse('news', $newsPost);
 }
 public function autoComplete()
 {
     $f = new ARSelectFilter();
     $f->setLimit(20);
     $resp = array();
     $field = $this->request->get('field');
     if ('specField_' == substr($field, 0, 10)) {
         list($foo, $id) = explode('_', $field);
         $handle = new ARFieldHandle('EavStringValue', 'value');
         $locale = $this->locale->getLocaleCode();
         $searchHandle = MultilingualObject::getLangSearchHandle($handle, $locale);
         $f->setCondition(new EqualsCond(new ARFieldHandle('EavStringValue', 'fieldID'), $id));
         $f->mergeCondition(new LikeCond($handle, '%:"' . $this->request->get($field) . '%'));
         $f->mergeCondition(new LikeCond($searchHandle, $this->request->get($field) . '%'));
         $f->setOrder($searchHandle, 'ASC');
         $results = ActiveRecordModel::getRecordSet('EavStringValue', $f);
         foreach ($results as $value) {
             $resp[$value->getValueByLang('value', $locale, MultilingualObject::NO_DEFAULT_VALUE)] = true;
         }
         $resp = array_keys($resp);
     }
     return new AutoCompleteResponse($resp);
 }
Example #22
0
 public function getSelectFilter($searchTerm)
 {
     // create initial index
     if (0 && !SearchableItem::getRecordCount()) {
         $app = ActiveRecordModel::getApplication();
         $sc = new SearchableConfigurationIndexing($app->getConfig(), $app);
         $sc->buildIndex(null);
     }
     $c = new ARExpressionHandle($this->getWeighedSearchCondition(array('value' => 1), $searchTerm));
     $app = ActiveRecordModel::getApplication();
     $f = new ARSelectFilter(new MoreThanCond($c, 0));
     $f->mergeCondition(new OrChainCondition(array(eq(f('SearchableItem.locale'), $app->getDefaultLanguageCode()), eq(f('SearchableItem.locale'), $app->getLocaleCode()), isnull(f('SearchableItem.locale')))));
     $f->setOrder(f('SearchableItem.sort'), 'DESC');
     $f->setOrder($c, 'DESC');
     return $f;
 }
Example #23
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);
 }
 private static function getAsignedToFilter($productOrID, $filter = null)
 {
     if (!$filter) {
         $filter = new ARSelectFilter();
     }
     if (is_numeric($productOrID)) {
         $productIDs = array((int) $productOrID);
     } else {
         if (is_array($productOrID)) {
             $productIDs = $productOrID;
         } else {
             if (is_object($productOrID) && $productOrID instanceof Product) {
                 $productIDs = array($productOrID->getID());
             } else {
                 throw new Exception('getAsignedToFilter() excpects argument to be instance of Product');
             }
         }
     }
     $filter->mergeCondition(new InCond(new ARFieldHandle(__CLASS__, 'productID'), $productIDs));
     return $filter;
 }
Example #25
0
File: User.php Project: saiber/www
 public function getOrder($id)
 {
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'ID'), $id));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $this->getID()));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
     $s = ActiveRecordModel::getRecordSet('CustomerOrder', $f, ActiveRecordModel::LOAD_REFERENCES);
     if ($s->size()) {
         $order = $s->get(0);
         $order->loadAll();
         return $order;
     }
 }
 /**
  * Load groups to roles associations as array from database using specified group
  *
  * @param UserGroup $userGroup User group
  * @param ARSelectFilter $filter
  * @param bool $loadReferencedRecords
  *
  * @return Array
  */
 public static function getRecordSetArrayByUserGroup(UserGroup $userGroup, ARSelectFilter $filter, $loadReferencedRecords = false)
 {
     $filter->mergeCondition(new EqualsCond(new ARFieldHandle(__CLASS__, "userGroupID"), $userGroup->getID()));
     return self::getRecordSetArray(__CLASS__, $filter, $loadReferencedRecords);
 }
Example #27
0
 private function getSelectFilter($class)
 {
     if ('Product' == $class) {
         $cat = Category::getRootNode();
         $f = $cat->getProductFilter(new ARSelectFilter());
         $f->mergeCondition($cat->getProductCondition(true));
         $f->joinTable('Category', 'Product', 'ID', 'categoryID');
         return $f;
     }
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle($class, 'ID'));
     if ('StaticPage' != $class) {
         $f->setCondition(new EqualsCond(new ARFieldHandle($class, 'isEnabled'), true));
     }
     if ('Category' == $class) {
         $f->mergeCondition(new NotEqualsCond(new ARFieldHandle($class, 'ID'), Category::ROOT_ID));
     }
     return $f;
 }
Example #28
0
 protected function oldboxRootCategoryBlock()
 {
     ClassLoader::import('application.model.staticpage.StaticPage');
     if ($this->config->get('TOP_MENU_HIDE')) {
         return;
     }
     if (!$this->config->get('TOP_MENU_HIDE_CATS')) {
         $topCategories = $this->getTopCategories($this->config->get('CAT_MENU_TOP_ROOT'));
         $ids = array();
         foreach ($topCategories as $cat) {
             if ($cat['isEnabled']) {
                 $ids[] = $cat['ID'];
             }
         }
         $f = new ARSelectFilter(new INCond(new ARFieldHandle('Category', 'parentNodeID'), $ids));
         $f->setOrder(new ARFieldHandle('Category', 'parentNodeID'));
         $f->setOrder(new ARFieldHandle('Category', 'lft'));
         $subCategories = array();
         foreach (ActiveRecordModel::getRecordSetArray('Category', $f) as $cat) {
             if ($cat['isEnabled']) {
                 $subCategories[$cat['parentNodeID']][] = $cat;
             }
         }
     }
     $f = new ARSelectFilter(new IsNullCond(new ARFieldHandle('StaticPage', 'parentID')));
     $f->mergeCondition(StaticPage::getIsRootCategoriesMenuCondition());
     $f->setOrder(new ARFieldHandle('StaticPage', 'position'));
     $pages = ActiveRecordModel::getRecordSetArray('StaticPage', $f);
     $ids = array();
     $subPages = array();
     foreach ($pages as $page) {
         $ids[] = $page['ID'];
     }
     $f = new ARSelectFilter(new INCond(new ARFieldHandle('StaticPage', 'parentID'), $ids));
     $f->setOrder(new ARFieldHandle('StaticPage', 'position'));
     foreach (ActiveRecordModel::getRecordSetArray('StaticPage', $f) as $page) {
         $subPages[$page['parentID']][] = $page;
     }
     if (empty($topCategories) && empty($pages)) {
         return;
     }
     $response = new BlockResponse();
     $response->set('categories', $topCategories);
     $response->set('subCategories', $subCategories);
     $response->set('pages', $pages);
     $response->set('subPages', $subPages);
     $response->set('currentId', $this->getTopCategoryId());
     return $response;
 }
Example #29
0
 /**
  * Provides an additional verification that state belongs to the particular country
  *
  * @return ActiveRecord
  */
 public static function getStateByIDAndCountry($stateID, $countryID)
 {
     $f = new ARSelectFilter();
     $f->setCondition(new EqualsCond(new ARFieldHandle('State', 'ID'), $stateID));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('State', 'countryID'), $countryID));
     $f->setLimit(1);
     $states = ActiveRecordModel::getRecordSet('State', $f);
     if ($states) {
         return $states->get(0);
     } else {
         return null;
     }
 }
Example #30
0
 /**
  * Calculate a delivery rate for a particular shipment
  *
  * @return ShipmentDeliveryRate
  */
 public function getDeliveryRate(Shipment $shipment)
 {
     $hasFreeShipping = false;
     // get applicable rates
     if (self::WEIGHT_BASED == $this->rangeType->get()) {
         $weight = $shipment->getChargeableWeight($this->deliveryZone->get());
         $cond = new EqualsOrLessCond(new ARFieldHandle('ShippingRate', 'weightRangeStart'), $weight * 1.000001);
         $cond->addAND(new EqualsOrMoreCond(new ARFieldHandle('ShippingRate', 'weightRangeEnd'), $weight * 0.99999));
     } else {
         $total = $shipment->getSubTotal(Shipment::WITHOUT_TAXES);
         $cond = new EqualsOrLessCond(new ARFieldHandle('ShippingRate', 'subtotalRangeStart'), $total * 1.000001);
         $cond->addAND(new EqualsOrMoreCond(new ARFieldHandle('ShippingRate', 'subtotalRangeEnd'), $total * 0.99999));
     }
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('ShippingRate', 'shippingServiceID'), $this->getID()));
     $f->mergeCondition($cond);
     $rates = ActiveRecordModel::getRecordSet('ShippingRate', $f);
     if (!$rates->size()) {
         return null;
     }
     $itemCount = $shipment->getChargeableItemCount($this->deliveryZone->get());
     $maxRate = 0;
     foreach ($rates as $rate) {
         $charge = $rate->flatCharge->get();
         foreach ($shipment->getItems() as $item) {
             $charge += $rate->getItemCharge($item) * $item->getCount();
         }
         if (self::WEIGHT_BASED == $this->rangeType->get()) {
             $charge += $rate->perKgCharge->get() * $weight;
         } else {
             $charge += $rate->subtotalPercentCharge->get() / 100 * $total;
         }
         if ($charge > $maxRate) {
             $maxRate = $charge;
         }
     }
     return ShipmentDeliveryRate::getNewInstance($this, $maxRate);
 }