Esempio n. 1
0
 /**
  * Create new user group
  *
  * @param DeliveryZone $deliveryZone Delivery zone instance
  * @param Tax $tax Tax type
  * @param float $rate Rate in percents
  * @return TaxRate
  */
 public static function getNewInstance($name, $description = '')
 {
     $instance = ActiveRecord::getNewInstance(__CLASS__);
     $instance->name->set($name);
     $instance->description->set($description);
     return $instance;
 }
Esempio n. 2
0
 /**
  * @return DeliveryZoneCountry
  */
 public static function getNewInstance(DeliveryZone $zone, $countryCode)
 {
     $instance = ActiveRecord::getNewInstance(__CLASS__);
     $instance->deliveryZone->set($zone);
     $instance->countryCode->set($countryCode);
     return $instance;
 }
Esempio n. 3
0
 /**
  * @return DeliveryZoneState
  */
 public static function getNewInstance(DeliveryZone $zone, $mask)
 {
     $instance = ActiveRecord::getNewInstance(__CLASS__);
     $instance->deliveryZone->set($zone);
     $instance->mask->set($mask);
     return $instance;
 }
 /**
  * Associate new role to user group
  *
  * @param UserGroup $userGroup User group
  * @param Role $role Associate group with this role
  * @return Tax
  */
 public static function getNewInstance(UserGroup $userGroup, Role $role)
 {
     $instance = ActiveRecord::getNewInstance(__CLASS__);
     $instance->userGroup->set($userGroup);
     $instance->role->set($role);
     return $instance;
 }
Esempio n. 5
0
 /**
  * Create new shipping rate instance
  *
  * @param ShippingService $shippingService Shipping service instance
  * @param float $rangeStart Lower range limit
  * @param float $rangeEnd Higher range limit
  * @return ShippingRate
  */
 public static function getNewInstance(ShippingService $shippingService, $rangeStart, $rangeEnd)
 {
     $instance = ActiveRecord::getNewInstance(__CLASS__);
     $instance->shippingService->set($shippingService);
     $instance->setRangeStart($rangeStart);
     $instance->setRangeEnd($rangeEnd);
     return $instance;
 }
Esempio n. 6
0
 /**
  * Create new tax rate
  *
  * @param DeliveryZone $deliveryZone Delivery zone instance
  * @param Tax $tax Tax type
  * @param float $rate Rate in percents
  * @return TaxRate
  */
 public static function getNewInstance(DeliveryZone $deliveryZone = null, Tax $tax, $rate)
 {
     $instance = ActiveRecord::getNewInstance(__CLASS__);
     if ($deliveryZone) {
         $instance->deliveryZone->set($deliveryZone);
     }
     $instance->tax->set($tax);
     $instance->rate->set($rate);
     return $instance;
 }
Esempio n. 7
0
 /**
  * @role create
  */
 public function add()
 {
     try {
         $newCurrency = ActiveRecord::getNewInstance('Currency');
         $newCurrency->setId($this->request->get('id'));
         $newCurrency->save(ActiveRecord::PERFORM_INSERT);
         return new JSONResponse($newCurrency->toArray());
     } catch (Exception $exc) {
         return new JSONResponse(0);
     }
 }
Esempio n. 8
0
 public static function getNewInstance(RecurringProductPeriod $recurringProductPeriod, OrderedItem $item, $setupPrice = null, $periodPrice = null, $rebillCount = null)
 {
     $instance = ActiveRecord::getNewInstance(__CLASS__);
     $instance->orderedItem->set($item);
     $instance->setRecurringProductPeriod($recurringProductPeriod);
     // call after orderedItem is added!
     $instance->periodLength->set($recurringProductPeriod->periodLength->get());
     $instance->periodType->set($recurringProductPeriod->periodType->get());
     if ($setupPrice !== null) {
         $instance->setupPrice->set($setupPrice);
     }
     if ($periodPrice !== null) {
         $instance->periodPrice->set($periodPrice);
     }
     if ($rebillCount !== null) {
         $instance->rebillCount->set($rebillCount);
     }
     return $instance;
 }
Esempio n. 9
0
 /**
  * @role create
  */
 public function add()
 {
     try {
         $newCurrency = ActiveRecord::getNewInstance('Currency');
         $newCurrency->setId($this->request->get('id'));
         $config = $this->getApplication()->getConfig();
         // if can use external currency rate source
         if ($config->get('CURRENCY_RATE_UPDATE')) {
             // get exchange rate from external currency rate source
             $source = CurrencyRateSource::getInstance($this->application, null, array($newCurrency->getID()));
             $rate = $source->getRate($newCurrency->getID());
             if ($rate != null) {
                 $newCurrency->rate->set($rate);
             }
         }
         $newCurrency->save(ActiveRecord::PERFORM_INSERT);
         return new JSONResponse($newCurrency->toArray());
     } catch (Exception $exc) {
         return new JSONResponse(0);
     }
 }
Esempio n. 10
0
 public function testSerializeSpeed()
 {
     for ($k = 1; $k <= 10; $k++) {
         $record = ActiveRecord::getNewInstance('SerializedModel');
         $record->setID($k);
         $record->name->set('some name ' . $k);
         $record->save();
     }
     ActiveRecord::clearPool();
     // fetch from database
     $fetchTime = microtime(true);
     $set = ActiveRecord::getRecordSet('SerializedModel', new ARSelectFilter());
     $fetchTime = microtime(true) - $fetchTime;
     $serialized = serialize($set);
     ActiveRecord::clearPool();
     // unserialize
     $serTime = microtime(true);
     $set = unserialize($serialized);
     $serTime = microtime(true) - $serTime;
     $this->assertTrue($serTime < $fetchTime);
 }
Esempio n. 11
0
 public static function getNewInstance(Category $category)
 {
     $catImage = ActiveRecord::getNewInstance(__CLASS__);
     $catImage->category->set($category);
     return $catImage;
 }
Esempio n. 12
0
 /**
  * @return DeliveryZone
  */
 public static function getNewInstance()
 {
     return ActiveRecord::getNewInstance(__CLASS__);
 }
Esempio n. 13
0
 public function createChildProduct()
 {
     $child = ActiveRecord::getNewInstance(__CLASS__);
     $child->parent->set($this);
     return $child;
 }
Esempio n. 14
0
 public static function getNewInstance(Product $product)
 {
     $image = ActiveRecord::getNewInstance(__CLASS__);
     $image->product->set($product);
     return $image;
 }
Esempio n. 15
0
 /**
  * Create new shipping class
  *
  * @param string $$defaultLanguageName Type name spelled in default language
  * @return TaxClass
  */
 public static function getNewInstance($defaultLanguageName)
 {
     $instance = ActiveRecord::getNewInstance(__CLASS__);
     $instance->setValueByLang('name', null, $defaultLanguageName);
     return $instance;
 }
Esempio n. 16
0
 public function setConfig()
 {
     if (!$this->buildConfigValidator()->isValid()) {
         return new ActionRedirectResponse('install', 'config');
     }
     Language::deleteCache();
     // site name
     $this->config->setValueByLang('STORE_NAME', $this->request->get('language'), $this->request->get('name'));
     $this->config->save();
     ClassLoader::import('application.model.Currency');
     // create currency
     if (ActiveRecord::objectExists('Currency', $this->request->get('curr'))) {
         $currency = Currency::getInstanceByID($this->request->get('curr'), Currency::LOAD_DATA);
     } else {
         $currency = ActiveRecord::getNewInstance('Currency');
         $currency->setID($this->request->get('curr'));
         $currency->isEnabled->set(true);
         $currency->isDefault->set(true);
         $currency->save(ActiveRecord::PERFORM_INSERT);
     }
     ClassLoader::import('application.model.system.Language');
     // create language
     if (ActiveRecord::objectExists('Language', $this->request->get('language'))) {
         $language = Language::getInstanceByID($this->request->get('language'), Language::LOAD_DATA);
     } else {
         $language = ActiveRecord::getNewInstance('Language');
         $language->setID($this->request->get('language'));
         $language->save(ActiveRecord::PERFORM_INSERT);
         $language->isEnabled->set(true);
         $language->isDefault->set(true);
         $language->save();
     }
     // set root category name to "LiveCart"
     ClassLoader::import('application.model.category.Category');
     $root = Category::getInstanceById(Category::ROOT_ID, Category::LOAD_DATA);
     $root->setValueByLang('name', $language->getID(), 'LiveCart');
     $root->save();
     // create a default shipping service
     ClassLoader::import('application.model.delivery.DeliveryZone');
     ClassLoader::import('application.model.delivery.ShippingService');
     ClassLoader::import('application.model.delivery.ShippingRate');
     $service = ShippingService::getNewInstance(DeliveryZone::getDefaultZoneInstance(), 'Default Service', ShippingService::SUBTOTAL_BASED);
     $service->save();
     $rate = ShippingRate::getNewInstance($service, 0, 100000);
     $rate->flatCharge->set(10);
     $rate->save();
     // create a couple of blank static pages
     ClassLoader::import('application.model.staticpage.StaticPage');
     $page = StaticPage::getNewInstance();
     $page->setValueByLang('title', $language->getID(), 'Contact Info');
     $page->setValueByLang('text', $language->getID(), 'Enter your contact information here');
     $page->menu->set(array('INFORMATION' => true));
     $page->save();
     $page = StaticPage::getNewInstance();
     $page->setValueByLang('title', $language->getID(), 'Shipping Policy');
     $page->setValueByLang('text', $language->getID(), 'Enter your shipping rate & policy information here');
     $page->menu->set(array('INFORMATION' => true));
     $page->save();
     // create an example site news post
     ClassLoader::import('application.model.sitenews.NewsPost');
     $news = ActiveRecordModel::getNewInstance('NewsPost');
     $news->setValueByLang('title', $language->getID(), 'Our store is open');
     $news->setValueByLang('text', $language->getID(), 'Powered by LiveCart software, we have gone live! Of course, we will have to go to <a href="../backend">the backend area</a> and add some categories and products first...');
     $news->setValueByLang('moreText', $language->getID(), 'Do not forget to delete this post when you actually go live :)');
     $news->isEnabled->set(true);
     $news->save();
     return new ActionRedirectResponse('install', 'finish');
 }
Esempio n. 17
0
 /**
  * Add new language
  * @role create
  * @return JSONResponse
  */
 public function add()
 {
     $lang = ActiveRecord::getNewInstance('Language');
     $lang->setID($this->request->get("id"));
     $lang->save(ActiveRecord::PERFORM_INSERT);
     return new JSONResponse(array('language' => $lang->toArray()), 'success', $this->translate('_new_language_was_successfully_added'));
 }
Esempio n. 18
0
 public static function getNewInstance(Manufacturer $manufacturer)
 {
     $image = ActiveRecord::getNewInstance(__CLASS__);
     $image->manufacturer->set($manufacturer);
     return $image;
 }
Esempio n. 19
0
 /**
  * Create new role rate
  *
  * @param string $name New role name
  * @return Role
  */
 public static function getNewInstance($name)
 {
     $instance = ActiveRecord::getNewInstance(__CLASS__);
     $instance->name->set($name);
     return $instance;
 }