public static function restoreInstance($className, ActiveRecordModel $owner, EavFieldCommon $field, $value) { $specItem = parent::getInstanceByID($className, array(call_user_func(array($className, 'getOwnerIDColumnName')) => $owner->getID(), call_user_func(array($className, 'getFieldIDColumnName')) => $field->getID())); $specItem->value->set($value); $specItem->resetModifiedStatus(); return $specItem; }
protected function save(ActiveRecordModel $listGroup) { $validator = $this->buildValidator(); if ($validator->isValid()) { $listGroup->loadRequestData($this->request); $listGroup->save(); return new JSONResponse(array('ID' => $listGroup->getID(), 'data' => $listGroup->toArray()), 'success'); } else { return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure'); } }
public static function getNewInstance(Product $product, ProductVariation $variation) { $instance = parent::getNewInstance(__CLASS__); $instance->product->set($product); $instance->variation->set($variation); return $instance; }
public static function getNewInstance(CustomerOrder $order, User $user) { $instance = parent::getNewInstance(__CLASS__); $instance->order->set($order); $instance->user->set($user); return $instance; }
/** * Create new advertiser */ public static function getNewInstance(ClonedStore $store, $type) { $instance = parent::getNewInstance(__CLASS__); $instance->store->set($store); $instance->type->set($type); return $instance; }
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); }
public function setUp() { parent::setUp(); $this->controller = new EavFieldController(self::getApplication()); ActiveRecordModel::executeUpdate('DELETE FROM EavField'); ActiveRecordModel::executeUpdate('DELETE FROM EavFieldGroup'); }
public function getUrl() { $params = array(); // user name $params['merchant'] = $this->getConfigValue('merchant'); if ($this->getConfigValue('test')) { $params['test'] = 'yes'; } // A seller reference number for a transaction $params['orderid'] = $this->details->invoiceID->get(); $params['uniqueoid'] = $this->details->invoiceID->get(); // The payment amount $params['amount'] = $this->details->amount->get() * 100; // The currency code of the payment amount. $params['currency'] = $this->getCurrency($this->details->currency->get()); //$this->notifyUrl = preg_replace('/currency\=[A-Z]{3}/', '', $this->notifyUrl); $params['callbackurl'] = $this->notifyUrl; $params['accepturl'] = $this->returnUrl; $params['cancelurl'] = $this->siteUrl; $params['lang'] = ActiveRecordModel::getApplication()->getLocaleCode(); $params['skiplastpage'] = 1; $params['md5key'] = $this->getMd5Key($params); $pairs = array(); foreach ($params as $key => $value) { $pairs[] = $key . '=' . urlencode($value); } return 'https://payment.architrade.com/paymentweb/start.action?' . implode('&', $pairs); }
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)); }
protected function getInstance($record, CsvImportProfile $profile) { $fields = $profile->getSortedFields(); if (isset($fields['ProductReview']['ID'])) { $instance = ActiveRecordModel::getInstanceByID('ProductReview', $record[$fields['ProductReview']['ID']], true); } else { if (isset($fields['Product']['ID'])) { $parent = ActiveRecordModel::getInstanceByID('Product', $record[$fields['Product']['ID']], true); } else { if (isset($fields['Product']['sku'])) { $parent = Product::getInstanceBySku($record[$fields['Product']['sku']]); } else { return; } } } if (empty($instance) && empty($parent)) { return; } if (empty($instance)) { $instance = ProductReview::getNewInstance($parent, User::getNewInstance('')); $instance->isEnabled->set(true); } return $instance; }
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); }
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; }
/** * Reorder pages * * @role sort */ public function reorder() { $inst = StaticPage::getInstanceById($this->request->get('id'), StaticPage::LOAD_DATA); $f = new ARSelectFilter(); $handle = new ARFieldHandle('StaticPage', 'position'); if ('down' == $this->request->get('order')) { $f->setCondition(new MoreThanCond($handle, $inst->position->get())); $f->setOrder($handle, 'ASC'); } else { $f->setCondition(new LessThanCond($handle, $inst->position->get())); $f->setOrder($handle, 'DESC'); } $f->setLimit(1); $s = ActiveRecordModel::getRecordSet('StaticPage', $f); if ($s->size()) { $pos = $inst->position->get(); $replace = $s->get(0); $inst->position->set($replace->position->get()); $replace->position->set($pos); $inst->save(); $replace->save(); return new JSONResponse(array('id' => $inst->getID(), 'order' => $this->request->get('order')), 'success'); } else { return new JSONResponse(false, 'failure', $this->translate('_could_not_reorder_pages')); } }
public function setUp() { parent::setUp(); ActiveRecordModel::executeUpdate('DELETE FROM ClonedStore'); $this->usd = ActiveRecordModel::getNewInstance('Currency'); $this->usd->setID('ZZZ'); $this->usd->save(ActiveRecord::PERFORM_INSERT); @unlink(ClonedStoreUpdater::getTimestampFile()); @unlink(ClonedStoreUpdater::getIDFile()); // create stores for ($k = 0; $k <= 0; $k++) { $this->stores[$k] = ClonedStore::getNewInstance(); $this->stores[$k]->domain->set($k); $this->stores[$k]->save(); echo $this->stores[$k]->lastImport->get(); } // create categories $root = Category::getRootNode(); for ($k = 0; $k <= 5; $k++) { $this->categories[] = $this->createCategory($root, $k); } $this->categories['1.1'] = $this->createCategory($this->categories[1], '1.1'); $this->categories['1.2'] = $this->createCategory($this->categories[1], '1.2'); $this->categories['1.2.1'] = $this->createCategory($this->categories['1.2'], '1.2.1'); $this->categories['1.2.2'] = $this->createCategory($this->categories['1.2'], '1.2.2'); usleep(1500000); }
public static function getNewInstance(OrderedItem $item, ProductFile $file) { $instance = parent::getNewInstance(__CLASS__); $instance->orderedItem->set($item); $instance->productFile->set($file); return $instance; }
public function testClone() { $text = EavField::getNewInstance('User', EavField::DATATYPE_TEXT, EavField::TYPE_TEXT_SIMPLE); $text->save(); $singleSel = EavField::getNewInstance('User', EavField::DATATYPE_NUMBERS, EavField::TYPE_NUMBERS_SELECTOR); $singleSel->handle->set('single.sel'); $singleSel->setValueByLang('name', 'en', 'Select one value'); $singleSel->save(); $value1 = EavValue::getNewInstance($singleSel); $value1->setValueByLang('value', 'en', $firstValue = '20'); $value1->save(); $value2 = EavValue::getNewInstance($singleSel); $value2->setValueByLang('value', 'en', $secValue = '30'); $value2->save(); $user = User::getNewInstance('*****@*****.**'); $user->save(); $spec = $user->getSpecification(); $spec->setAttributeValueByLang($text, 'en', 'text'); $spec->setAttributeValue($singleSel, $value1); $user->save(); $cloned = clone $user; $cloned->email->set('*****@*****.**'); $cloned->save(); $this->assertNotSame($cloned->getSpecification(), $user->getSpecification()); $this->assertEquals($cloned->getSpecification()->getAttribute($text)->getValueByLang('value', 'en'), 'text'); ActiveRecordModel::clearPool(); $reloaded = ActiveRecordModel::getInstanceByID('User', $cloned->getID(), true); $this->assertEquals($reloaded->getSpecification()->getAttribute($text)->getValueByLang('value', 'en'), 'text'); $this->assertEquals($reloaded->getSpecification()->getAttribute($singleSel)->getValue()->get()->getID(), $value1->getID()); }
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; }
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; }
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); }
public static function getNewInstance(CustomerOrder $order, $code) { $instance = parent::getNewInstance(__CLASS__); $instance->order->set($order); $instance->couponCode->set($code); return $instance; }
private function getLanguageIDs() { if (!$this->langIDs) { $this->langIDs = ActiveRecordModel::getApplication()->getLanguageArray(true); } return $this->langIDs; }
/** * Creates array representation * * @return array */ protected static function transformArray($array, ARSchema $schema) { if (!empty($array['serializedData'])) { $array['serializedData'] = unserialize($array['serializedData']); } return parent::transformArray($array, $schema); }
public static function deleteByID($className, $id, $foreignKeyName) { $inst = ActiveRecordModel::getInstanceById($className, $id, ActiveRecordModel::LOAD_DATA); $inst->getOwner()->load(); $inst->deleteImageFiles(); // check if main image is being deleted $owner = $inst->getOwner(); $owner->load(array(get_class($inst))); if ($owner->defaultImage->get()->getID() == $id) { // set next image (by position) as the main image $f = new ARSelectFilter(); $cond = new EqualsCond(new ARFieldHandle(get_class($inst), $foreignKeyName), $owner->getID()); $cond->addAND(new NotEqualsCond(new ARFieldHandle(get_class($inst), 'ID'), $inst->getID())); $f->setCondition($cond); $f->setOrder(new ARFieldHandle(get_class($inst), 'position')); $f->setLimit(1); $newDefaultImage = ActiveRecordModel::getRecordSet(get_class($inst), $f); if ($newDefaultImage->size() > 0) { $owner->defaultImage->set($newDefaultImage->get(0)); $owner->save(); } } ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=0'); ActiveRecordModel::executeUpdate('UPDATE ' . $className . ' SET ' . $foreignKeyName . '=NULL , protectedFields="|' . $foreignKeyName . '|" WHERE ID=' . $id); //return parent::deleteByID($className, $id); }
public static function getNewInstance(Product $product, ProductRatingType $type = null) { $instance = parent::getNewInstance(__CLASS__); $instance->product->set($product); $instance->ratingType->set($type); return $instance; }
public function testSimpleImport() { $lv = ActiveRecordModel::getNewInstance('Language'); $lv->setID('xx'); $lv->save(); $profile = new CsvImportProfile('Product'); $profile->setField(0, 'Product.sku'); $profile->setField(1, 'Product.name', array('language' => 'en')); $profile->setField(2, 'Product.name', array('language' => 'xx')); $profile->setField(3, 'Product.shippingWeight'); $profile->setParam('delimiter', ';'); $csvFile = ClassLoader::getRealPath('cache.') . 'testDataImport.csv'; file_put_contents($csvFile, 'test; "Test Product"; "Parbaudes Produkts"; 15' . "\n" . 'another; "Another Test"; "Vel Viens"; 12.44'); $import = new ProductImport($this->getApplication()); $csv = $profile->getCsvFile($csvFile); $cnt = $import->importFile($csv, $profile); $this->assertEquals($cnt, 2); $test = Product::getInstanceBySKU('test'); $this->assertTrue($test instanceof Product); $this->assertEquals($test->shippingWeight->get(), '15'); $this->assertEquals($test->getValueByLang('name', 'en'), 'Test Product'); $another = Product::getInstanceBySKU('another'); $this->assertEquals($another->getValueByLang('name', 'xx'), 'Vel Viens'); unlink($csvFile); }
public function getSelectFilter($disableFilters = false) { $selectFilter = $this->category->getProductsFilter($this, false); $selectFilter->merge($this->productFilter); $cond = null; if ($disableFilters == false) { $list = array(); // group filters by class foreach ($this->filters as $filter) { $id = $filter instanceof SpecificationFilterInterface ? $filter->getFilterGroup()->getID() : ''; $list[get_class($filter) . '_' . $id][] = $filter->getCondition(); $filter->defineJoin($selectFilter); } // convert filter group to OrChainCondition foreach ($list as &$filterGroup) { $filterGroup = new OrChainCondition($filterGroup); } if ($fCond = $selectFilter->getCondition()) { $list[] = $fCond; } $selectFilter->setCondition(new AndChainCondition($list)); // all merged with and } ActiveRecordModel::getApplication()->processInstancePlugins('finalProductFilter', $selectFilter); return $selectFilter; }
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); }
public static function getNewInstanceByUser(NewsletterMessage $message, User $user) { $instance = parent::getNewInstance(__CLASS__); $instance->message->set($message); $instance->user->set($user); return $instance; }
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; }
/** * Create new campaign */ public static function getNewInstance(Category $category, ClonedStore $store) { $instance = parent::getNewInstance(__CLASS__); $instance->category->set($category); $instance->store->set($store); return $instance; }