public function delete()
 {
     $product = Product::getInstanceByID($this->request->get('id'), ActiveRecord::LOAD_DATA, array('Category'));
     $category = Category::getInstanceByID($this->request->get('categoryId'), ActiveRecord::LOAD_DATA);
     $relation = ActiveRecordModel::getInstanceById('ProductCategory', array('productID' => $product->getID(), 'categoryID' => $category->getID()));
     $relation->delete();
     return new JSONResponse(array('data' => $relation->toFlatArray()));
 }
Example #2
0
 public function saveCategories()
 {
     $store = $this->getStore();
     if ('nochange' != $this->request->get('categories')) {
         $store->deleteRelatedRecordSet('ClonedStoreCategory');
         foreach (explode(',', $this->request->get('categories')) as $cat) {
             ClonedStoreCategory::getNewInstance(Category::getInstanceByID($cat), $store)->save();
         }
     }
     return new JSONResponse(null, 'success', 'Store category settings saved successfully');
 }
 public function create()
 {
     $parentId = $this->request->get('parentID', false);
     if (substr($parentId, 0, 1) == 'c') {
         $parent = Category::getInstanceByID(substr($parentId, 1));
     } else {
         $parent = Product::getInstanceByID($parentId);
     }
     $productOption = ProductOption::getNewInstance($parent);
     return $this->save($productOption);
 }
Example #4
0
 /**
  * @role update
  */
 public function save()
 {
     $validator = $this->buildValidator();
     if (!$validator->isValid()) {
         return new JSONResponse(array('err' => $validator->getErrorList()));
     }
     $post = $this->request->get('id') ? ActiveRecordModel::getInstanceById('ProductRatingType', $this->request->get('id'), ActiveRecordModel::LOAD_DATA) : ProductRatingType::getNewInstance(Category::getInstanceByID($this->request->get('categoryId'), Category::LOAD_DATA));
     $post->loadRequestData($this->request);
     $post->save();
     return new JSONResponse($post->toArray());
 }
 public function addCategory()
 {
     $category = Category::getInstanceByID($this->request->get('id'), ActiveRecord::LOAD_DATA, array('Category'));
     $relatedCategory = Category::getInstanceByID($this->request->get('categoryId'), ActiveRecord::LOAD_DATA);
     // check if the category is not assigned to this category already
     $f = select(eq('CategoryRelationship.relatedCategoryID', $relatedCategory->getID()));
     if ($category->getRelatedRecordSet('CategoryRelationship', $f)->size()) {
         return new JSONResponse(false, 'failure', $this->translate('_err_already_assigned'));
     }
     $relation = CategoryRelationship::getNewInstance($category, $relatedCategory);
     $relation->save();
     $relatedCategory->getPathNodeSet();
     return new JSONResponse(array('data' => $relation->toFlatArray()));
 }
 private function _testStringSerialize($string, $equals = true)
 {
     error_reporting(E_WARNING);
     $root = Category::getInstanceByID(1);
     $new = Category::getNewInstance($root);
     $new->setValueByLang('name', 'en', $string);
     $new->save();
     ActiveRecordModel::clearPool();
     $restored = Category::getInstanceByID($new->getID(), Category::LOAD_DATA);
     if ($equals) {
         $this->assertEqual($string, $restored->getValueByLang('name', 'en'));
     } else {
         $this->assertNotEquals($string, $restored->getValueByLang('name', 'en'));
     }
     error_reporting(E_ALL);
 }
 public function index()
 {
     $categoryID = (int) $this->request->get('id');
     $category = Category::getInstanceByID($categoryID, ActiveRecord::LOAD_DATA);
     // get lists
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle('ProductList', 'position'));
     $lists = $category->getRelatedRecordSetArray('ProductList', $f);
     $ids = array();
     foreach ($lists as $list) {
         $ids[] = $list['ID'];
     }
     // get list items
     $f = new ARSelectFilter(new INCond(new ARFieldHandle('ProductListItem', 'productListID'), $ids));
     $f->setOrder(new ARFieldHandle('ProductList', 'position'));
     $f->setOrder(new ARFieldHandle('ProductListItem', 'productListID'));
     $f->setOrder(new ARFieldHandle('ProductListItem', 'position'));
     $items = ActiveRecordModel::getRecordSetArray('ProductListItem', $f, array('ProductList', 'Product', 'ProductImage'));
     $items = ActiveRecordGroup::mergeGroupsWithFields('ProductList', $lists, $items);
     $response = new ActionResponse();
     $response->set('ownerID', $categoryID);
     $response->set('items', $items);
     return $response;
 }
Example #8
0
 private function _getCategoryById($id, $includeRootNode = false)
 {
     if ($includeRootNode == false && $id == $this->root->getID()) {
         throw new Exception('Cannot change root level category.');
     }
     $category = Category::getInstanceByID($id, true);
     // if id is not integer getInstanceByID() will not throw exception?
     // could remove next 3 lines, if all ID come from ModelApi::getRequestID(), but they not (parent node id, for example)
     if (false == $category->getID() > 0) {
         throw new Exception('Bad ID field value.');
     }
     return $category;
 }
Example #9
0
 private function getCategoryByPath($profile, $names)
 {
     if (!is_array($names)) {
         $names = explode(' / ', $names);
     }
     $hash = '';
     $hashRoot = $this->getRoot($profile)->getID();
     $cat = null;
     foreach ($names as $name) {
         $hash .= "\n" . $name;
         if (!isset($this->categories[$hash])) {
             $f = Category::getInstanceByID($hashRoot)->getSubcategoryFilter();
             $f->mergeCondition(new EqualsCond(MultiLingualObject::getLangSearchHandle(new ARFieldHandle('Category', 'name'), $this->application->getDefaultLanguageCode()), $name));
             $cat = ActiveRecordModel::getRecordSet('Category', $f)->get(0);
             if (!$cat) {
                 $cat = Category::getNewInstance(Category::getInstanceByID($hashRoot));
                 $cat->isEnabled->set(true);
                 $cat->setValueByLang('name', $this->application->getDefaultLanguageCode(), $name);
                 $cat->save();
             }
             $this->categories[$hash] = $cat->getID();
         }
         $hashRoot = $this->categories[$hash];
         $cat = Category::getInstanceByID($hashRoot, true);
     }
     return $cat;
 }
Example #10
0
 public function xmlRecursivePath()
 {
     $xmlResponse = new XMLResponse();
     $targetID = (int) $this->request->get("id");
     try {
         $categoriesList = Category::getInstanceByID($targetID)->getPathBranchesArray();
         if (count($categoriesList) > 0 && isset($categoriesList['children'][0]['parent'])) {
             $xmlResponse->set("rootID", $categoriesList['children'][0]['parent']);
             $xmlResponse->set("categoryList", $categoriesList);
         }
         $xmlResponse->set("doNotTouch", $this->request->get("doNotTouch"));
     } catch (Exception $e) {
     }
     $xmlResponse->set("targetID", $targetID);
     return $xmlResponse;
 }
Example #11
0
 public function __construct()
 {
     parent::__construct('Product files tests');
     $this->tmpFilePath = ClassLoader::getRealPath('cache.') . 'somefile.txt';
     $this->rootCategory = Category::getInstanceByID(Category::ROOT_ID);
 }
Example #12
0
 protected function boxRootCategoryBlock()
 {
     $rootID = $this->config->get('CAT_MENU_TOP_ROOT');
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('Category', 'isEnabled'), true));
     $categories = ActiveRecordModel::getRecordSetArray('Category', Category::getInstanceByID($rootID, true)->getBranchFilter($f));
     $tree = array($rootID => array('subCategories' => array()));
     foreach ($categories as $key => &$category) {
         $tree[$category['ID']] =& $category;
     }
     foreach ($categories as &$category) {
         $tree[$category['parentNodeID']]['subCategories'][] =& $category;
     }
     $tree = $tree[$rootID]['subCategories'];
     $response = new BlockResponse('categories', $tree);
     $path = $this->getCategory()->getPathNodeArray();
     if ($path) {
         $response->set('topCategoryId', $path[0]['ID']);
     }
     $response->set('currentId', $this->getCategory()->getID());
     $response->set('currentCategory', $this->getCategory()->toArray());
     return $response;
 }
Example #13
0
 protected function getSelectFilter()
 {
     $id = $this->getID();
     if ($this->isCategory()) {
         $owner = Category::getInstanceByID($id, Category::LOAD_DATA);
         $cond = new EqualsOrMoreCond(new ARFieldHandle('Category', 'lft'), $owner->lft->get());
         $cond->addAND(new EqualsOrLessCond(new ARFieldHandle('Category', 'rgt'), $owner->rgt->get()));
     } else {
         $cond = new EqualsCond(new ARFieldHandle('ProductReview', 'productID'), $id);
     }
     return new ARSelectFilter($cond);
 }
Example #14
0
 /**
  * @role create
  */
 public function create()
 {
     $product = Product::getNewInstance(Category::getInstanceByID($this->request->get('categoryID')), $this->translate('_new_product'));
     $response = $this->save($product);
     if ($response instanceof ActionResponse) {
         $response->get('productForm')->clearData();
         $response->set('id', $product->getID());
         return $response;
     } else {
         return $response;
     }
 }
 public function __construct()
 {
     parent::__construct('Related product tests');
     $this->rootCategory = Category::getInstanceByID(Category::ROOT_ID);
 }
Example #16
0
 public function __construct()
 {
     parent::__construct('Specification fields test');
     $this->rootCategory = Category::getInstanceByID(ActiveTreeNode::ROOT_ID);
 }
Example #17
0
 private function getTopCategories()
 {
     ClassLoader::import('application.model.category.Category');
     if (!isset($this->topCategories)) {
         $this->topCategories = Category::getInstanceByID(1)->getSubcategoryArray();
     }
     return $this->topCategories;
 }
Example #18
0
 public function recursivePath()
 {
     $root = Category::getRootNode()->toArray();
     if ($this->request->get("id") == $root['ID']) {
         return;
     }
     $root['children'] = array(Category::getInstanceByID((int) $this->request->get("id"), true)->getPathBranchesArray());
     return new JSONResponse($this->getRecursiveJson($root));
 }
Example #19
0
 private function buildPathBranchesArray($path, $level)
 {
     $branch = array();
     if (!isset($path[$level]['ID'])) {
         return $branch;
     }
     $branch['children'] = Category::getInstanceByID($path[$level]['ID'])->getChildNodes(false, true)->toArray();
     $childrenCount = count($branch['children']);
     $pathCount = count($path);
     for ($i = 0; $i < $childrenCount; $i++) {
         if ($level + 1 < $pathCount && $branch['children'][$i]['ID'] == $path[$level + 1]['ID']) {
             $branch['children'][$i] = array_merge($branch['children'][$i], $this->buildPathBranchesArray($path, $level + 1));
         }
     }
     return $branch;
 }
Example #20
0
 public function __construct()
 {
     parent::__construct('Product file groups tests');
     $this->rootCategory = Category::getInstanceByID(Category::ROOT_ID);
 }
Example #21
0
 public function __construct()
 {
     parent::__construct('Product pricings');
     // Get root category
     $this->category = Category::getInstanceByID(Category::ROOT_ID);
 }
Example #22
0
 public function specFields()
 {
     $form = new Form($this->getValidator('specField'));
     if ($this->request->get('id')) {
         $product = Product::getInstanceByID((int) $this->request->get('id'), ActiveRecord::LOAD_DATA);
     } else {
         $cat = Category::getInstanceByID((int) $this->request->get('categoryID'), ActiveRecord::LOAD_DATA);
         $product = Product::getNewInstance($cat);
     }
     $product->loadSpecification();
     $response = new BlockResponse('form', $form);
     $product->getSpecification()->setFormResponse($response, $form);
     $product->getSpecification()->setValidation($form->getValidator());
     return $response;
 }
Example #23
0
 private function getFeaturedMainCategoryProducts(&$categories)
 {
     $cache = $this->application->getCache();
     $namespace = 'category_featured';
     $products = array();
     foreach ((array) $categories as $category) {
         $key = array($namespace, $category['ID']);
         if ($product = $cache->get($key)) {
             $products[] = $product;
             continue;
         }
         $cat = Category::getInstanceByID($category['ID'], Category::LOAD_DATA);
         $pf = new ProductFilter($cat, new ARSelectFilter());
         $pf->includeSubcategories();
         $f = $cat->getProductsFilter($pf);
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('Product', 'isFeatured'), true));
         $f->setLimit(1);
         $f->setOrder(new ARExpressionHandle('RAND()'));
         $product = array_pop(ActiveRecordModel::getRecordSetArray('Product', $f, array('ProductImage', 'Category', 'Manufacturer')));
         if (!$product) {
             $product = array('ID' => 0);
         }
         $cache->set($key, $product, 1800);
         $products[] = $product;
     }
     ProductPrice::loadPricesForRecordSetArray($products);
     foreach ($products as $key => $product) {
         $categories[$key]['featuredProduct'] = $product;
     }
 }
 protected function getParent($id)
 {
     return Category::getInstanceByID($id);
 }
Example #25
0
 /**
  * Get filter group data from database
  *
  * @role update
  *
  * @return JSONResponse
  */
 public function item()
 {
     $groupID = $this->request->get('id');
     $categoryID = $this->request->get('categoryID');
     $response = new ActionResponse();
     $filterGroup = FilterGroup::getInstanceByID($groupID, true, array('SpecField', 'Category'));
     $filterGroupArray = $filterGroup->toArray();
     foreach ($filterGroup->getFiltersList() as $filter) {
         $filterGroupArray['filters'][$filter->getID()] = $filter->toArray(false);
     }
     if ($filterGroup->specField->get()->isSelector()) {
         $filterGroupArray['filtersCount'] = $filterGroup->specField->get()->getValuesSet()->getTotalRecordCount();
     } else {
         $filterGroupArray['filtersCount'] = isset($filterGroupArray['filters']) ? count($filterGroupArray['filters']) : 0;
     }
     $filterGroupArray['rootId'] = "filter_items_list_" . $categoryID . "_" . $filterGroupArray['ID'];
     $filterGroupArray['categoryID'] = $categoryID;
     $filterGroupArray['specFields'] = $this->getSpecFieldOptions(Category::getInstanceByID($categoryID, ActiveRecord::LOAD_DATA)->getSpecificationFieldArray());
     return new JSONResponse($filterGroupArray);
 }
Example #26
0
 public function delimiters()
 {
     $file = $this->request->get('file');
     if (!file_exists($file)) {
         return new ActionRedirectResponse('backend.csvImport', 'index');
     }
     // try to guess the delimiter
     foreach ($this->delimiters as $delimiter) {
         $csv = new CsvFile($file, $delimiter);
         unset($count);
         foreach ($this->getPreview($csv) as $row) {
             if (!isset($count)) {
                 $count = count($row);
             }
             if ($count != count($row)) {
                 unset($count);
                 break;
             }
         }
         if (isset($count) && $count > 1) {
             break;
         } else {
             $delimiter = ',';
         }
     }
     if (!$delimiter) {
         $delimiter = ',';
     }
     $form = $this->getDelimiterForm();
     $form->set('options', $this->request->get('options'));
     $form->set('delimiter', $delimiter);
     $form->set('file', $file);
     $form->set('type', $this->request->get('type'));
     $form->set('category', $this->request->get('category'));
     $response = new ActionResponse();
     $response->set('form', $form);
     $response->set('file', $file);
     $delimiters = array_flip($this->delimiters);
     foreach ($delimiters as &$title) {
         $title = $this->translate($title);
     }
     $response->set('delimiters', $delimiters);
     $csv = new CsvFile($file, $delimiter);
     $preview = $this->getPreview($csv);
     $response->set('type', $this->request->get('type'));
     $response->set('preview', $preview);
     $response->set('previewCount', count($preview));
     $response->set('total', $csv->getRecordCount());
     $response->set('currencies', $this->application->getCurrencyArray());
     $response->set('languages', $this->application->getLanguageSetArray(true));
     $response->set('groups', ActiveRecordModel::getRecordSetArray('UserGroup', new ARSelectFilter()));
     $response->set('catPath', Category::getInstanceByID($this->request->get('category'), Category::LOAD_DATA)->getPathNodeArray(true));
     $profiles = array('' => '');
     foreach ((array) glob($this->getProfileDirectory($this->getImportInstance()) . '*.ini') as $path) {
         $profile = basename($path, '.ini');
         $profiles[$profile] = $profile;
     }
     $response->set('profiles', $profiles);
     return $response;
 }
Example #27
0
 public function setUp()
 {
     parent::setUp();
     $this->root = Category::getInstanceByID(ActiveTreeNode::ROOT_ID, true);
 }
Example #28
0
 /**
  *  Enabled product, with some stock - the numbers should increase by one
  */
 public function testCategoryCountsWhenEnabledProductWithNoStockIsAdded()
 {
     $secondCategory = Category::getNewInstance($this->productCategory);
     $secondCategory->save();
     $product = Product::getNewInstance($secondCategory);
     $product->isEnabled->set(1);
     $product->stockCount->set(0);
     $product->save();
     ActiveRecordModel::removeFromPool($secondCategory);
     $sameCategory = Category::getInstanceByID($secondCategory->getID(), true);
     $this->assertEqual((int) $secondCategory->activeProductCount->get() + 1, (int) $sameCategory->activeProductCount->get());
     $this->assertEqual((int) $secondCategory->availableProductCount->get(), (int) $sameCategory->availableProductCount->get());
     // now add some stock, so available product count should increase by one
     $product->stockCount->set(5);
     $product->save();
     ActiveRecordModel::removeFromPool($sameCategory);
     $sameCategory = Category::getInstanceByID($secondCategory->getID(), true);
     $this->assertEqual((int) $secondCategory->availableProductCount->get() + 1, (int) $sameCategory->availableProductCount->get());
 }
Example #29
0
 public function previous($diff = -1)
 {
     $product = Product::getInstanceByID($this->request->get('id'), true, array('Category'));
     $this->category = !$this->request->get('category') ? $product->category->get() : Category::getInstanceByID($this->request->get('category'), true);
     $this->getAppliedFilters();
     $this->getSelectFilter();
     if ($this->request->get('quickShopSequence')) {
         $ids = json_decode($this->request->get('quickShopSequence'));
     } else {
         $ids = array();
         foreach (ActiveRecordModel::getFieldValues('Product', $this->productFilter->getSelectFilter(), array('ID'), array('Category')) as $row) {
             $ids[] = $row['ID'];
         }
     }
     $index = array_search($product->getID(), $ids);
     $prevIndex = $index + $diff;
     if ($prevIndex < 0) {
         $prevIndex = count($ids) - 1;
     } else {
         if ($prevIndex == count($ids)) {
             $prevIndex = 0;
         }
     }
     include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.productUrl.php';
     if ('quickShop' == $this->request->get('originalAction')) {
         return new ActionRedirectResponse('product', 'quickShop', array('id' => $ids[$prevIndex], 'query' => $this->getContext()));
     } else {
         return new RedirectResponse(createProductUrl(array('product' => Product::getInstanceByID($ids[$prevIndex], true)->toArray(), 'query' => $this->getContext()), $this->application));
     }
 }