public function getNumber()
 {
     $config = ActiveRecordModel::getApplication()->getConfig();
     $startAt = $config->get('SequentialInvoiceNumber_START_AT');
     $prefix = $config->get('SequentialInvoiceNumber_PREFIX');
     $suffix = $config->get('SequentialInvoiceNumber_SUFFIX');
     // get last finalized order
     $last = array_pop(ActiveRecord::getRecordSetArray('CustomerOrder', $this->getSelectFilter()));
     $lastNumber = $last ? $last['invoiceNumber'] : $startAt;
     if (substr($lastNumber, 0, strlen($prefix)) == $prefix) {
         $lastNumber = substr($lastNumber, strlen($prefix));
     }
     if (substr($lastNumber, -1 * strlen($suffix)) == $suffix) {
         $lastNumber = substr($lastNumber, 0, -1 * strlen($suffix));
     }
     preg_match('/[0-9]+/', $lastNumber, $matches);
     $lastNumber = array_shift($matches);
     if ($lastNumber < $startAt) {
         $lastNumber = $startAt;
     }
     // avoid selecting the same order if the invoice number is already taken
     $this->getSelectFilter()->mergeCondition(neq('CustomerOrder.ID', $last['ID']));
     $lastNumber += max($config->get('SequentialInvoiceNumber_STEP'), 1);
     $lastNumber = str_pad($lastNumber, $config->get('SequentialInvoiceNumber_MIN_LENGTH'), '0', STR_PAD_LEFT);
     $lastNumber = $prefix . $lastNumber . $suffix;
     return $lastNumber;
 }
Esempio n. 2
0
 public function edit()
 {
     $newsletter = ActiveRecordModel::getInstanceById('NewsletterMessage', $this->request->get('id'), ActiveRecordModel::LOAD_DATA);
     $form = $this->getForm();
     $form->setData($newsletter->toArray());
     $form->set('users', 1);
     $form->set('subscribers', 1);
     $response = new ActionResponse('form', $form);
     $groupsArray = array_merge(ActiveRecord::getRecordSetArray('UserGroup', select()), array(array('ID' => null, 'name' => $this->translate('Customers'))));
     usort($groupsArray, array($this, 'sortGroups'));
     $response->set('groupsArray', $groupsArray);
     $newsletterArray = $newsletter->toArray();
     $text = strlen($newsletterArray['text']);
     $html = strlen($newsletterArray['html']);
     if ($text && $html) {
         $newsletterArray['format'] = self::FORMAT_HTML_TEXT;
     } else {
         if ($text) {
             $newsletterArray['format'] = self::FORMAT_TEXT;
         } else {
             if ($html) {
                 $newsletterArray['format'] = self::FORMAT_HTML;
             }
         }
     }
     $response->set('newsletter', $newsletterArray);
     $response->set('sentCount', $newsletter->getSentCount());
     $response->set('recipientCount', $this->getRecipientCount($form->getData()));
     return $response;
 }
Esempio n. 3
0
 protected function insert()
 {
     // get max position
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle(__CLASS__, 'categoryID'), $this->getCategory()->getID()));
     $f->setOrder(new ARFieldHandle(get_class($this), 'position'), 'DESC');
     $f->setLimit(1);
     $rec = ActiveRecord::getRecordSetArray(get_class($this), $f);
     $position = is_array($rec) && count($rec) > 0 ? $rec[0]['position'] + 1 : 1;
     $this->position->set($position);
     return parent::insert();
 }
Esempio n. 4
0
 private function getShippingMethods()
 {
     ClassLoader::import('application.model.delivery.ShippingService');
     $methods = array();
     $f = select();
     $f->setOrder(f('DeliveryZone.ID'));
     $f->setOrder(f('ShippingService.position'));
     foreach (ActiveRecord::getRecordSetArray('ShippingService', $f, array('DeliveryZone')) as $service) {
         $methods[$service['ID']] = $service['name_lang'] . ' (' . $service['DeliveryZone']['name'] . ')';
     }
     return $methods;
 }
Esempio n. 5
0
 public function testInstanceMemoryUsage()
 {
     $f = new ARSelectFilter();
     $f->setLimit(1000);
     ActiveRecord::getRecordSetArray('DiscountCondition', $f);
     $arrayMem = memory_get_usage();
     $array = ActiveRecord::getRecordSetArray('DiscountCondition', $f);
     $arrayMem = memory_get_usage() - $arrayMem;
     echo count($arrayMem) . "\n";
     echo $arrayMem . "\n";
     $arraySet = memory_get_usage();
     $array = ActiveRecord::getRecordSet('DiscountCondition', $f);
     $arraySet = memory_get_usage() - $arraySet;
     echo $arraySet . "\n";
 }
Esempio n. 6
0
 public function bestsellingProductsBlock()
 {
     ClassLoader::import('application.model.product.ProductFilter');
     $cache = $this->application->getCache();
     $key = array('bestsellers', $this->getCategory()->getID() . '_' . $days);
     if (!$cache->get($key)) {
         $category = $this->getCategory();
         $filter = new ProductFilter($category, new ARSelectFilter());
         $filter->includeSubcategories();
         $filter->setEnabledOnly();
         $selectFilter = $filter->getSelectFilter();
         $selectFilter->setLimit($this->config->get('BESTSELLING_ITEMS_COUNT'));
         $selectFilter->setOrder(new ARExpressionHandle('cnt'), 'DESC');
         $q = new ARSelectQueryBuilder();
         $q->includeTable('Product');
         $q->joinTable('Category', 'Product', 'ID', 'categoryID');
         $q->addField('Product.ID');
         $q->addField(new ARExpressionHandle('(SELECT SUM(count) FROM OrderedItem LEFT JOIN CustomerOrder ON OrderedItem.customerOrderID=CustomerOrder.ID WHERE productID=Product.ID AND CustomerOrder.isPaid=1 AND CustomerOrder.dateCompleted > "' . ARSerializableDateTime::createFromTimeStamp(strtotime('-' . $this->config->get('BESTSELLING_ITEMS_DAYS') . ' days')) . '")'), null, 'cnt');
         $q->setFilter($selectFilter);
         $cache->set($key, ActiveRecord::getDataByQuery($q));
     }
     $products = $cache->get($key);
     if (!$products) {
         return;
     }
     $ids = array();
     foreach ($products as $id) {
         $ids[] = $id['ID'];
     }
     $products = ActiveRecord::getRecordSetArray('Product', select(IN('Product.ID', $ids)), array('DefaultImage' => 'ProductImage'));
     ProductPrice::loadPricesForRecordSetArray($products);
     if ($products) {
         return new BlockResponse('products', $products);
     }
 }
Esempio n. 7
0
 protected function insert()
 {
     // get max position
     $f = new ARSelectFilter(self::getFilter($this->product->get())->getCondition());
     $f->setOrder(new ARFieldHandle(__CLASS__, "position"), 'DESC');
     $f->setLimit(1);
     $rec = ActiveRecord::getRecordSetArray(__CLASS__, $f);
     $position = is_array($rec) && count($rec) > 0 ? $rec[0]['position'] + 1 : 0;
     $this->position->set($position);
     return parent::insert();
 }
Esempio n. 8
0
 /**
  * Returns a set of category filters
  *
  * @param bool $loadReferencedRecords
  * @return ARSet
  */
 public function getFilterGroupArray()
 {
     if (null === $this->filterGroupArrayCache) {
         ClassLoader::import('application.model.filter.FilterGroup');
         $filter = $this->getFilterGroupFilter();
         if (!$filter) {
             $this->filterGroupArrayCache = array();
         } else {
             $this->filterGroupArrayCache = ActiveRecord::getRecordSetArray('FilterGroup', $filter, array('SpecField'));
         }
     }
     return $this->filterGroupArrayCache;
 }
Esempio n. 9
0
 protected function setLastPosition($parentField = null, ARValueMapper $parent = null)
 {
     if ($parentField && !$parent) {
         $parent = $this->{$parentField};
     }
     $parentField .= 'ID';
     // get max position
     $cond = $parent ? new EqualsCond(new ARFieldHandle(get_class($this), $parentField), $parent->get()->getID()) : null;
     $f = new ARSelectFilter($cond);
     $f->setOrder(new ARFieldHandle(get_class($this), 'position'), 'DESC');
     $f->setLimit(1);
     $rec = ActiveRecord::getRecordSetArray(get_class($this), $f);
     $position = is_array($rec) && count($rec) > 0 ? $rec[0]['position'] + 1 : 0;
     // default new language state
     $this->position->set($position);
 }
 private function initLocales()
 {
     ClassLoader::import('library.locale.Locale');
     $filter = new ARSelectFilter();
     $filter->setOrder(new ARFieldHandle("Language", "position"), ARSelectFilter::ORDER_ASC);
     $filter->setCondition(new EqualsCond(new ARFieldHandle("Language", "isEnabled"), 1));
     if (count($this->limitToLocales) > 0) {
         $z = array();
         foreach ($this->limitToLocales as $localeCode) {
             $z[] = new EqualsCond(new ARFieldHandle("Language", "ID"), $localeCode);
         }
         $filter->mergeCondition(new OrChainCondition($z));
         // new INCond()
     }
     $languages = ActiveRecord::getRecordSetArray("Language", $filter);
     foreach ($languages as $language) {
         $locale = Locale::getInstance($language['ID']);
         $locale->translationManager()->setCacheFileDir(ClassLoader::getRealPath('storage.language'));
         foreach ($this->application->getConfigContainer()->getLanguageDirectories() as $dir) {
             $locale->translationManager()->setDefinitionFileDir($dir);
         }
         $locale->translationManager()->setDefinitionFileDir(ClassLoader::getRealPath('storage.language'));
         $locale->translationManager()->loadFile('backend/Settings');
         $this->locales[$language['ID']] = $locale;
     }
     $this->localeCodes = array_keys($this->locales);
 }
Esempio n. 11
0
 protected function loadData()
 {
     ActiveRecord::clearArrayData();
     $this->data = ActiveRecord::getRecordSetArray($this->table, $this->filter, $this->referencedRecords);
 }
Esempio n. 12
0
 private function getComparedProducts()
 {
     $filter = Category::getRootNode()->getProductFilter(select(IN('Product.ID', $this->getComparedProductIDs())));
     $products = ActiveRecord::getRecordSetArray('Product', $filter, array('Category', 'ProductImage'));
     ProductSpecification::loadSpecificationForRecordSetArray($products, true);
     ProductPrice::loadPricesForRecordSetArray($products);
     return $products;
 }
Esempio n. 13
0
 private function updateRuleCache()
 {
     $paths = array();
     $app = ActiveRecordModel::getApplication();
     foreach (array('condition', 'action') as $type) {
         $path = 'application.model.businessrule.' . $type;
         foreach ($app->getPluginClasses($path) as $class) {
             $paths[$class] = $app->getPluginClassPath($path, $class);
         }
     }
     $f = select(eq('DiscountCondition.isEnabled', true));
     $f->setOrder(f('DiscountCondition.position'));
     $conditions = ActiveRecord::getRecordSetArray('DiscountCondition', $f);
     $idMap = array();
     foreach ($conditions as &$condition) {
         $idMap[$condition['ID']] =& $condition;
     }
     // get condition records
     foreach (ActiveRecord::getRecordSetArray('DiscountConditionRecord', select(), array('Category')) as $record) {
         $idMap[$record['conditionID']]['records'][] = $record;
     }
     // get actions
     $f = select();
     $f->setOrder(f('DiscountAction.position'));
     foreach (ActiveRecord::getRecordSetArray('DiscountAction', $f) as $action) {
         if (!empty($action['actionConditionID'])) {
             $action['condition'] =& $idMap[$action['actionConditionID']];
         }
         $idMap[$action['conditionID']]['actions'][] = $action;
     }
     foreach ($conditions as &$condition) {
         if (!$condition['parentNodeID'] || !isset($idMap[$condition['parentNodeID']]) || !empty($condition['isActionCondition'])) {
             continue;
         }
         $idMap[$condition['parentNodeID']]['sub'][] =& $condition;
     }
     $rootCond = RuleCondition::createFromArray($idMap[DiscountCondition::ROOT_ID]);
     file_put_contents(self::getRuleFile(), '<?php $paths = ' . var_export($paths, true) . '; foreach ($paths as $path) { include_once($path); } return ' . var_export(serialize($rootCond->getConditions()), true) . '; ?>');
 }
Esempio n. 14
0
 protected function insert()
 {
     // get max position
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle('StaticPage', 'position'), 'DESC');
     $f->setLimit(1);
     $rec = ActiveRecord::getRecordSetArray('StaticPage', $f);
     $position = is_array($rec) && count($rec) > 0 ? $rec[0]['position'] + 1 : 1;
     $this->position->set($position);
     return parent::insert();
 }
Esempio n. 15
0
 protected function insert()
 {
     // get max position
     $f = self::getRelatedProductsSetFilter($this->product->get(), $this->type->get());
     $f->setLimit(1);
     $rec = ActiveRecord::getRecordSetArray('ProductRelationship', $f);
     $position = is_array($rec) && count($rec) > 0 ? $rec[0]['position'] + 1 : 0;
     $this->position->set($position);
     return parent::insert();
 }
Esempio n. 16
0
    public function getProductsPurchasedTogether($limit = null, $enabledOnly = false)
    {
        if (0 === $limit) {
            return array();
        }
        if (is_null($limit)) {
            $limit = 0;
        }
        $sql = 'SELECT
					COUNT(*) AS cnt, COALESCE(ParentProduct.ID, OtherItem.productID) AS ID FROM OrderedItem
				LEFT JOIN
					CustomerOrder ON OrderedItem.customerOrderID=CustomerOrder.ID
				LEFT JOIN
					OrderedItem AS OtherItem ON OtherItem.customerOrderID=CustomerOrder.ID
				LEFT JOIN
					Product ON OtherItem.productID=Product.ID
				LEFT JOIN
					Product AS ParentProduct ON Product.parentID=ParentProduct.ID
				WHERE
					CustomerOrder.isFinalized=1 AND OrderedItem.productID=' . $this->getID() . ' AND OtherItem.productID!=' . $this->getID() . ($enabledOnly ? ' AND Product.isEnabled=1' : '') . '
				GROUP
					BY OtherItem.productID
				ORDER BY
					cnt DESC
				LIMIT ' . (int) $limit;
        $products = ActiveRecord::getDataBySql($sql);
        $ids = array();
        $cnt = array();
        foreach ($products as $key => $prod) {
            $ids[] = $prod['ID'];
            $cnt[$prod['ID']] = empty($cnt[$prod['ID']]) ? $prod['cnt'] : $prod['cnt'] + $cnt[$prod['ID']];
        }
        $products = array();
        if ($ids) {
            $products = ActiveRecord::getRecordSetArray('Product', new ARSelectFilter(new INCond(new ARFieldHandle('Product', 'ID'), $ids)), array('DefaultImage' => 'ProductImage'));
            foreach ($products as &$prod) {
                $prod['count'] = $cnt[$prod['ID']];
            }
            usort($products, array($this, 'togetherStatsSort'));
            ProductPrice::loadPricesForRecordSetArray($products);
        }
        return $products;
    }
Esempio n. 17
0
 /**
  * Loads a list of child records for this node
  *
  * @param bool $loadReferencedRecords
  * @param bool $loadOnlyDirectChildren
  * @return ARSet
  *
  * @see self::getDirectChildNodes()
  */
 public function getChildNodeArray($loadReferencedRecords = false, $loadOnlyDirectChildren = false)
 {
     $className = get_class($this);
     $filter = $this->getChildNodeFilter($loadOnlyDirectChildren);
     return ActiveRecord::getRecordSetArray($className, $filter, $loadReferencedRecords);
 }