public function setUp() { parent::setUp(); ActiveRecord::clearPool(); ActiveRecord::executeUpdate('DELETE FROM Tax'); ActiveRecord::executeUpdate('DELETE FROM TaxRate'); ActiveRecord::executeUpdate('DELETE FROM DeliveryZone'); ActiveRecord::executeUpdate('DELETE FROM Currency'); ActiveRecord::executeUpdate('DELETE FROM ShippingService'); ActiveRecord::executeUpdate('DELETE FROM DeliveryZone'); ActiveRecord::executeUpdate('DELETE FROM TaxClass'); $this->deliveryZone = DeliveryZone::getNewInstance(); $this->deliveryZone->setValueByLang('name', 'en', 'test zone'); $this->deliveryZone->isEnabled->set(true); $this->deliveryZone->save(); DeliveryZoneCountry::getNewInstance($this->deliveryZone, 'US')->save(); $this->tax = Tax::getNewInstance('test type'); $this->tax->save(); $this->currency = ActiveRecord::getInstanceByIdIfExists('Currency', 'USD'); $this->currency->isEnabled->set(true); $this->currency->decimalCount->set(2); $this->currency->save(); $this->product = Product::getNewInstance(Category::getRootNode()); $this->product->setPrice('USD', 100); $this->product->isEnabled->set(true); $this->product->save(); $this->user = User::getNewInstance('*****@*****.**'); $this->user->save(); $this->address = UserAddress::getNewInstance(); $this->address->countryID->set('US'); $this->address->save(); $this->getApplication()->getConfig()->setRuntime('DELIVERY_TAX_CLASS', null); }
public function setUp() { parent::setUp(); BusinessRuleController::clearCache(); ActiveRecord::executeUpdate('DELETE FROM DeliveryZone'); ActiveRecord::executeUpdate('DELETE FROM Tax'); ActiveRecord::executeUpdate('DELETE FROM TaxRate'); ActiveRecord::executeUpdate('DELETE FROM DiscountCondition'); ActiveRecord::executeUpdate('DELETE FROM DiscountAction'); ActiveRecord::executeUpdate('DELETE FROM Currency'); $this->root = DiscountCondition::getRootNode(); $this->usd = ActiveRecordModel::getInstanceByIDIfExists('Currency', 'USD'); $this->usd->save(); $this->user = User::getNewInstance('discount.condition@test'); $this->user->save(); $this->order = CustomerOrder::getNewInstance($this->user); $this->order->currency->set($this->usd); $this->order->save(true); $this->product1 = Product::getNewInstance(Category::getRootNode()); $this->product1->isEnabled->set(true); $this->product1->setPrice('USD', 10); $this->product1->save(); $this->product2 = Product::getNewInstance(Category::getRootNode()); $this->product2->isEnabled->set(true); $this->product2->setPrice('USD', 20); $this->product2->save(); ActiveRecordModel::getApplication()->getConfig()->setRuntime('INVENTORY_TRACKING', 'DISABLE'); }
public function setDatabase() { set_time_limit(0); if (!$this->buildDatabaseValidator()->isValid()) { return new ActionRedirectResponse('install', 'database'); } $type = function_exists('mysql_connect') ? 'mysql' : 'mysqli'; $dsn = $type . '://' . $this->request->get('username') . ($this->request->get('password') ? ':' . $this->request->get('password') : '') . '@' . $this->request->get('server') . '/' . $this->request->get('name'); ClassLoader::import('library.activerecord.ActiveRecord'); ActiveRecord::resetDBConnection(); ActiveRecord::setDSN($dsn); try { $conn = ActiveRecord::getDBConnection(); // test if InnoDB tables can be created $table = 'TestInnoDB'; $create = 'CREATE TABLE ' . $table . ' (ID INTEGER) ENGINE = INNODB'; $drop = 'DROP TABLE ' . $table; ActiveRecord::executeUpdate($create); $data = ActiveRecord::getDataBySQL('SHOW TABLE STATUS'); ActiveRecord::executeUpdate($drop); foreach ($data as $row) { if (strtolower($row['Name']) == strtolower($table)) { if (strtolower($row['Engine']) != 'innodb') { throw new SQLException('', $this->translate('_err_innodb_not_available')); } } } $dsnFile = $this->getDsnFile(); if (!file_exists(dirname($dsnFile))) { mkdir(dirname($dsnFile), 0777, true); } ActiveRecord::beginTransaction(); //ActiveRecord::executeUpdate('SET FOREIGN_KEY_CHECKS = 0'); //ActiveRecord::executeUpdate('DROP TABLE `AccessControlAssociation`, `AdAdvertiser`, `AdAdvertiserUser`, `AdBanner`, `AdBannerStats`, `AdCampaign`, `AdCampaignCondition`, `AdZone`, `Author`, `AuthorImage`, `BillingAddress`, `Category`, `CategoryImage`, `CategoryPresentation`, `CategorySubscribeCategory`, `CategorySubscribeQueue`, `CategorySubscribeUser`, `Currency`, `CustomerOrder`, `DeliveryZone`, `DeliveryZoneAddressMask`, `DeliveryZoneCityMask`, `DeliveryZoneCountry`, `DeliveryZoneRealTimeService`, `DeliveryZoneState`, `DeliveryZoneWarehouse`, `DeliveryZoneZipMask`, `Discount`, `DiscountAction`, `DiscountCondition`, `DiscountConditionRecord`, `EavDateValue`, `EavField`, `EavFieldGroup`, `EavItem`, `EavNumericValue`, `EavObject`, `EavStringValue`, `EavValue`, `ExpressCheckout`, `Filter`, `FilterGroup`, `HelpComment`, `Language`, `Manufacturer`, `ManufacturerImage`, `NewsletterMessage`, `NewsletterSentMessage`, `NewsletterSubscriber`, `NewsPost`, `OrderCoupon`, `OrderDiscount`, `OrderedItem`, `OrderedItemOption`, `OrderLog`, `OrderNote`, `PostalCode`, `Product`, `ProductBundle`, `ProductCategory`, `ProductFile`, `ProductFileGroup`, `ProductImage`, `ProductList`, `ProductListItem`, `ProductOption`, `ProductOptionChoice`, `ProductPrice`, `ProductRating`, `ProductRatingSummary`, `ProductRatingType`, `ProductRelationship`, `ProductRelationshipGroup`, `ProductReview`, `ProductVariation`, `ProductVariationTemplate`, `ProductVariationType`, `ProductVariationValue`, `ProductWarehouse`, `PurchasePointsItemOrder`, `PurchasePointsOrder`, `PurchasePointsUser`, `RecurringProductPeriod`, `RewardPointsOrder`, `RewardPointsUser`, `Role`, `SearchLog`, `SessionData`, `Shipment`, `ShipmentTax`, `ShipmentWarehouse`, `ShippingAddress`, `ShippingRate`, `ShippingService`, `SpecField`, `SpecFieldGroup`, `SpecFieldValue`, `SpecificationDateValue`, `SpecificationItem`, `SpecificationNumericValue`, `SpecificationStringValue`, `State`, `StaticPage`, `Tax`, `TaxRate`, `Transaction`, `User`, `UserAddress`, `UserGroup`, `Warehouse`'); // import schema Installer::loadDatabaseDump(file_get_contents(ClassLoader::getRealPath('installdata.sql') . '/create.sql'), true); // create root category Installer::loadDatabaseDump(file_get_contents(ClassLoader::getRealPath('installdata.sql') . '/initialData.sql'), true); // states Installer::loadDatabaseDump(file_get_contents(ClassLoader::getRealPath('installdata.sql.state') . '/all.sql'), true); file_put_contents($dsnFile, '<?php return ' . var_export($dsn, true) . '; ?>'); ActiveRecord::commit(); return new ActionResponse(); //return new ActionRedirectResponse('install', 'admin'); } catch (SQLException $e) { $validator = $this->buildDatabaseValidator(); $validator->triggerError('connect', $e->getNativeError()); $validator->saveState(); return new ActionResponse('step', 'database'); //return new ActionRedirectResponse('install', 'database'); } }
public static function batchIncreaseProcessedRebillCount($ids) { if (count($ids) == 0) { return false; } ActiveRecord::executeUpdate('UPDATE ' . __CLASS__ . ' SET processedRebillCount = IF(processedRebillCount IS NULL, 1, processedRebillCount+1) WHERE ID IN(' . implode(',', $ids) . ')'); //ActiveRecordModel::ClearPool(); return true; }
public function updateSalesRank() { $cacheFile = ClassLoader::getRealPath('cache.salesrank'); if (!file_exists($cacheFile) || filemtime($cacheFile) < time() - 3600) { touch($cacheFile); ActiveRecord::executeUpdate('UPDATE Product SET salesRank=(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')) . '")'); } }
public function getNextCurrency() { if (!$this->currenciesTruncated) { ActiveRecord::executeUpdate('DELETE FROM Currency'); $this->currenciesTruncated = true; } if (!($data = $this->loadRecord('SELECT * FROM ' . $this->getTablePrefix() . 'currencies'))) { return null; } $curr = ActiveRecordModel::getInstanceByIdIfExists('Currency', $data['code']); $curr->pricePrefix->set($data['symbol_left']); $curr->priceSuffix->set($data['symbol_right']); $curr->rate->set($data['value']); $curr->lastUpdated->set($data['last_updated']); $curr->isEnabled->set(true); if ($this->getConfigValue('DEFAULT_CURRENCY') == $curr->getID()) { $curr->isDefault->set(true); } return $curr; }
public function loadDatabaseDump($dump, $flush = false, $force = false) { // newlines $dump = str_replace("\r", '', $dump); // clear comments $dump = preg_replace('/#.*#/', '', $dump); // get queries $queries = preg_split('/;\\n/', $dump); if ($flush && ob_get_length()) { ob_flush(); ob_end_clean(); } foreach ($queries as $query) { $query = trim($query); if (!empty($query)) { try { ActiveRecord::executeUpdate($query); } catch (Exception $e) { if (!$force) { throw $e; } } } if ($flush) { echo '.'; flush(); } } return true; }
public function removeUnnecessaryCategoriesFromSnapshot(ClonedStore $store) { $conds = array(); foreach ($store->getRelatedRecordSet('ClonedStoreCategory', select(), 'Category') as $storeCat) { $cat = $storeCat->category->get(); if (1 == $cat->getID()) { continue; } $cat->load(); $cond = lte(f('Category.lft'), $cat->lft->get()); $cond->addAND(gte(f('Category.rgt'), $cat->rgt->get())); $conds[] = $cond; } $this->flush(__LINE__); if (!$conds) { return; } $this->flush(__LINE__); $cond = new OrChainCondition($conds); $ids = array(); foreach (ActiveRecordModel::getFieldValues('Category', select($cond), array('ID')) as $id) { $ids[] = array_shift($id); } $idstr = 'IN (' . implode(', ', $ids) . ')'; // delete unused extra category references // ActiveRecord::executeUpdate('DELETE FROM ' . $this->importDatabase . '.ProductCategory WHERE categoryID NOT ' . $idstr); $this->flush(__LINE__); //var_dump('before: ' . array_shift(array_shift(ActiveRecord::getDataBySQL('SELECT COUNT(*) FROM ' . $this->importDatabase . '.Product')))); ActiveRecord::executeUpdate('DELETE FROM ' . $this->importDatabase . '.Product WHERE (categoryID NOT ' . $idstr . ') AND ((SELECT COUNT(*) FROM ' . $this->importDatabase . '.ProductCategory WHERE productID=Product.ID AND (ProductCategory.categoryID ' . $idstr . ')) = 0)'); //echo 'DELETE FROM ' . $this->importDatabase . '.Product WHERE (categoryID NOT ' . $idstr . ') AND ((SELECT COUNT(*) FROM ' . $this->importDatabase . '.ProductCategory WHERE productID=Product.ID AND (ProductCategory.categoryID ' . $idstr . ')) = 0)'; //var_dump('AFTER: ' . array_shift(array_shift(ActiveRecord::getDataBySQL('SELECT COUNT(*) FROM ' . $this->importDatabase . '.Product')))); //die('test'); $this->flush(__LINE__); // fix main category ActiveRecord::executeUpdate('UPDATE ' . $this->importDatabase . '.Product SET categoryID=(SELECT categoryID FROM ' . $this->importDatabase . '.ProductCategory WHERE productID=Product.ID AND ProductCategory.categoryID IN (' . implode(',', $ids) . ') LIMIT 1) WHERE (parentID IS NULL) AND (categoryID NOT ' . $idstr . ')'); $this->flush(__LINE__); // remove redundant extra categories ActiveRecord::executeUpdate('DELETE ' . $this->importDatabase . '.ProductCategory FROM ' . $this->importDatabase . '.ProductCategory LEFT JOIN ' . $this->importDatabase . '.Product ON ProductCategory.productID=Product.ID WHERE ProductCategory.categoryID=Product.categoryID'); $this->flush(__LINE__); // delete unused products ActiveRecord::executeUpdate('DELETE FROM ' . $this->importDatabase . '.Product WHERE (categoryID IS NULL) AND (parentID IS NULL)'); $this->flush(__LINE__); // get all remaining categories $sql = 'SELECT lft, rgt FROM ' . $this->importDatabase . '.Category WHERE ID IN (SELECT categoryID FROM ' . $this->importDatabase . '.ProductCategory)'; $conds = array(); foreach (ActiveRecordModel::getDataBySQL($sql) as $row) { $cond = lte(f('Category.lft'), $row['lft']); $cond->addAND(gte(f('Category.rgt'), $row['rgt'])); $conds[] = $cond; } $this->flush(__LINE__); $cond = new OrChainCondition($conds); $ids = array(); foreach (ActiveRecordModel::getFieldValues('Category', select($cond), array('ID')) as $id) { $ids[] = array_shift($id); } $this->flush(__LINE__); $allidstr = 'IN (' . implode(', ', $ids) . ')'; // delete unused categories ActiveRecord::executeUpdate('DELETE FROM ' . $this->importDatabase . '.Category WHERE (ID<>1) AND (ID NOT ' . $idstr . ') AND (ID NOT ' . $allidstr . ')'); $this->flush(__LINE__); // disable/enable existing products according to category selection $store->addQueuedQuery('UPDATE Category SET isEnabled=0 WHERE (ID NOT ' . $idstr . ') AND (ID NOT ' . $allidstr . ')'); $store->addQueuedQuery('UPDATE Category SET isEnabled=1 WHERE ((ID ' . $idstr . ') OR (ID ' . $allidstr . ')) AND (COALESCE(LOCATE("|isEnabled|", protectedFields), 0) = 0)'); $this->flush(__LINE__); $store->addQueuedQuery('UPDATE Product SET isEnabled=0 WHERE (parentID IS NULL) AND (categoryID NOT ' . $idstr . ') AND (categoryID NOT ' . $allidstr . ')'); //$store->addQueuedQuery('UPDATE Product SET isEnabled=1 WHERE (parentID IS NULL) AND ((categoryID ' . $idstr . ') OR (categoryID ' . $allidstr . ')) AND (COALESCE(LOCATE("|isEnabled|", protectedFields), 0) = 0)'); $this->flush(__LINE__); }
<?php include '../application/Initialize.php'; ClassLoader::import('application.LiveCart'); new LiveCart(); ClassLoader::import('application.model.product.Product'); ClassLoader::import('application.model.system.Installer'); $file = ClassLoader::getRealPath('installdata.demo') . '.sql'; //$file = 'alter.sql'; if (!file_exists($file)) { die('File not found: <strong>' . $file . '</strong>'); } set_time_limit(0); Product::getInstanceBySKU('test'); $dump = file_get_contents($file); // newlines $dump = str_replace("\r", '', $dump); // clear comments $dump = preg_replace('/#.*#/', '', $dump); // get queries $queries = preg_split('/;\\n/', $dump); foreach ($queries as $query) { $query = trim($query); if (!empty($query)) { ActiveRecord::executeUpdate($query); } }
public function setUp() { parent::setUp(); ActiveRecord::executeUpdate('DELETE FROM Currency'); ActiveRecord::executeUpdate('DELETE FROM DiscountCondition'); }