public function __construct(LiveCart $application, $database) { ini_set('memory_limit', '1700M'); set_time_limit(0); error_reporting(E_ALL); ini_set('display_errors', 'On'); Category::reindex(); Category::recalculateProductsCount(); $this->flush(__LINE__); $this->application = $application; $this->database = $database; $this->dbLogin = $this->getDBLogin(); $this->importDatabase = $database . '_import'; $this->flush(__LINE__); $this->timestamp = new ARSerializableDateTime(array_pop(array_pop(ActiveRecordModel::getDataBySQL('SELECT NOW()')))); $this->createSnapshot(); $this->flush(__LINE__); foreach (ActiveRecordModel::getDataBySQL('SHOW TABLES IN ' . $database) as $table) { $table = array_shift($table); if (!in_array($table, self::$ignoredTables)) { $this->tables[] = $table; } } $this->flush(__LINE__); }
public function saveMainCategory() { $product = Product::getInstanceByID($this->request->get('id'), ActiveRecord::LOAD_DATA, array('Category')); $category = Category::getInstanceByID($this->request->get('categoryId'), ActiveRecord::LOAD_DATA); $product->category->set($category); $product->save(); Category::recalculateProductsCount(); return new RawResponse($category->getID()); }
public function testCountRecalculate() { $this->root->totalProductCount->set(0); $this->categories[1]->totalProductCount->set(0); $this->categories[2]->totalProductCount->set(0); Category::recalculateProductsCount(); $this->reloadCategories(); $this->assertEquals(1, $this->categories[1]->totalProductCount->get()); $this->assertEquals(1, $this->categories[2]->totalProductCount->get()); $this->assertEquals(1, $this->root->totalProductCount->get()); }
public function import() { $this->application->setDevMode(true); ignore_user_abort(true); ini_set('memory_limit', '512M'); set_time_limit(0); if ($this->request->get('password') != $this->config->get('CLONE_STORE_API_KEY')) { return new RawResponse('Wrong password'); } ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=0;'); ActiveRecord::getLogger()->setLogFileName(null); $dir = $this->getFileDir(); //if (ob_get_length()) //{ ob_flush(); ob_end_clean(); //} //echo str_repeat('FLUSH ', 10000); foreach (scandir($dir) as $file) { if (strlen($file) < 3) { continue; } $path = $dir . $file; if (substr($file, -4) == '.sql') { $f = fopen($path, 'r'); $prev = ''; while (!feof($f)) { $s = $prev . fread($f, 1024 * 1024); if (!feof($f)) { $pos = strrpos($s, ";\n"); $prev = substr($s, $pos + 1); $s = substr($s, 0, $pos); } Installer::loadDatabaseDump($s, true); } } else { $this->untar($path, ClassLoader::getRealPath('public.upload.')); } unlink($path); } $this->user->allowBackendAccess(); $c = new ProductImageController($this->application); $c->resizeImages(); Category::reindex(); Category::recalculateProductsCount(); }
<?php error_reporting(E_ALL); ini_set('display_errors', 'On'); include '../application/Initialize.php'; ClassLoader::import('application.LiveCart'); new LiveCart(); ClassLoader::import('application.model.category.Category'); Category::getInstanceById(1); Category::recalculateProductsCount();
/** * @role mass */ public function processMass() { $filter = $this->getSelectFilter(); $act = $this->request->get('act'); $field = array_pop(explode('_', $act, 2)); if ('move' == $act) { new ActiveGrid($this->application, $filter, $this->getClassName()); $cat = Category::getInstanceById($this->request->get('categoryID'), Category::LOAD_DATA); $update = new ARUpdateFilter(); $update->setCondition($filter->getCondition()); $update->addModifier('Product.categoryID', $cat->getID()); $update->joinTable('ProductPrice', 'Product', 'productID AND (ProductPrice.currencyID = "' . $this->application->getDefaultCurrencyCode() . '")', 'ID'); ActiveRecord::beginTransaction(); ActiveRecord::updateRecordSet('Product', $update, Product::LOAD_REFERENCES); Category::recalculateProductsCount(); ActiveRecord::commit(); return new JSONResponse(array('act' => $this->request->get('act')), 'success', $this->translate('_move_succeeded')); } // remove design themes if ('theme' == $act && !$this->request->get('theme')) { ClassLoader::import('application.model.presentation.CategoryPresentation'); ActiveRecord::deleteRecordSet('CategoryPresentation', new ARDeleteFilter($filter->getCondition()), null, array('Product', 'Category')); return new JSONResponse(array('act' => $this->request->get('act')), 'success', $this->translate('_themes_removed')); } $params = array(); if ('manufacturer' == $act) { $params['manufacturer'] = Manufacturer::getInstanceByName($this->request->get('manufacturer')); } else { if ('price' == $act || 'inc_price' == $act) { $params['baseCurrency'] = $this->application->getDefaultCurrencyCode(); $params['price'] = $this->request->get($act); $params['currencies'] = $this->application->getCurrencySet(); $params['inc_price_value'] = $this->request->get('inc_price_value'); $params['inc_quant_price'] = $this->request->get('inc_quant_price'); } else { if ('addRelated' == $act) { $params['relatedProduct'] = Product::getInstanceBySKU($this->request->get('related')); if (!$params['relatedProduct']) { return new JSONResponse(0); } } else { if ($this->request->get('categoryID')) { $params['category'] = Category::getInstanceById($this->request->get('categoryID'), Category::LOAD_DATA); } else { if ('theme' == $act) { ClassLoader::import('application.model.presentation.CategoryPresentation'); $params['theme'] = $this->request->get('theme'); } else { if ('shippingClass' == $act) { $params['shippingClass'] = $this->request->get('shippingClass'); } else { if ('taxClass' == $act) { $params['taxClass'] = $this->request->get('taxClass'); } } } } } } } $response = parent::processMass($params); if ($this->request->get('categoryID')) { Category::recalculateProductsCount(); } return $response; }
public function afterImport() { Category::recalculateProductsCount(); }
/** * Reorder category node * * @role !category.sort */ public function reorder() { $targetNode = Category::getInstanceByID((int) $this->request->get("id")); $parentNode = Category::getInstanceByID((int) $this->request->get("parentId")); try { if ($direction = $this->request->get("direction", false)) { if (ActiveTreeNode::DIRECTION_LEFT == $direction) { $targetNode->moveLeft(false); } if (ActiveTreeNode::DIRECTION_RIGHT == $direction) { $targetNode->moveRight(false); } } else { $targetNode->moveTo($parentNode); } Category::reindex(); Category::recalculateProductsCount(); return new JSONResponse(false, 'success', $this->translate('_categories_tree_was_reordered')); } catch (Exception $e) { return new JSONResponse(false, 'failure', $this->translate('_unable_to_reorder_categories_tree')); } return new JSONResponse($status); }
public function testDiscountByAdditionalCategories() { $product = $this->products[1]; $condition = DiscountCondition::getNewInstance(); $condition->isEnabled->set(true); $condition->save(); $actionCondition = DiscountCondition::getNewInstance(); $actionCondition->isEnabled->set(true); $actionCondition->conditionClass->set('RuleConditionContainsProduct'); $actionCondition->save(); $action = DiscountAction::getNewInstance($condition); $action->actionCondition->set($actionCondition); $action->isEnabled->set(true); $action->type->set(DiscountAction::TYPE_ITEM_DISCOUNT); $action->amount->set(10); $action->actionClass->set('RuleActionPercentageDiscount'); $action->save(); $randomCategory = Category::getNewInstance(Category::getRootNode()); $randomCategory->save(); DiscountConditionRecord::getNewInstance($actionCondition, $randomCategory)->save(); $this->order->addProduct($product, 1, true); $this->order->save(); Category::recalculateProductsCount(); $product->reload(); $this->assertFalse(RuleCondition::create($actionCondition)->isProductMatching($product)); $customCategory = Category::getNewInstance(Category::getRootNode()); $customCategory->save(); ProductCategory::getNewInstance($product, $customCategory)->save(); DiscountConditionRecord::getNewInstance($actionCondition, $customCategory)->save(); Category::recalculateProductsCount(); $product->reload(); $actionCondition->loadAll(); $this->assertTrue(RuleCondition::create($actionCondition)->isProductMatching($product)); $this->assertEquals(count($this->order->getDiscountActions(true)), 1); $this->assertEquals($this->products[1]->getPrice($this->usd) * 0.9, $this->order->getTotal(true)); ActiveRecordModel::clearPool(); $order = CustomerOrder::getInstanceByID($this->order->getID()); $order->loadAll(); $this->assertEquals($this->products[1]->getPrice($this->usd) * 0.9, $this->order->getTotal(true)); }
/** * Reorder category node * * @role !category.sort */ public function move() { $targetNode = Category::getInstanceByID((int) $this->request->get("id")); $parentNode = Category::getInstanceByID((int) $this->request->get("parent")); $next = $this->request->get("next") ? Category::getInstanceByID((int) $this->request->get("next")) : null; try { $targetNode->moveTo($parentNode, $next); Category::reindex(); Category::recalculateProductsCount(); return new JSONResponse(false, 'success', $this->translate('_categories_tree_was_reordered')); } catch (Exception $e) { return new JSONResponse(false, 'failure', $this->translate('_unable_to_reorder_categories_tree')); } }