Exemplo n.º 1
0
 private function getFilterUrlTemplate()
 {
     include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php';
     $params = array('filters' => array(new ManufacturerFilter(999, '___')), 'data' => Category::getRootNode()->toArray());
     $templateUrl = createCategoryUrl($params, $this->application);
     return strtr($templateUrl, array(999 => '#', '___' => '|'));
 }
Exemplo n.º 2
0
 public function testDelete()
 {
     $type = ProductRatingType::getNewInstance(Category::getRootNode());
     $type->save();
     $type2 = ProductRatingType::getNewInstance(Category::getRootNode());
     $type2->save();
     for ($k = 0; $k <= 1; $k++) {
         $review = ProductReview::getNewInstance($this->product, $this->user);
         $review->save();
         $rating = ProductRating::getNewInstance($this->product, $type);
         $rating->rating->set(6 + $k);
         $rating->review->set($review);
         $rating->save();
         $rating = ProductRating::getNewInstance($this->product, $type2);
         $rating->rating->set(4 + $k);
         $rating->review->set($review);
         $rating->save();
     }
     $this->product->reload();
     $this->assertEqual($this->product->ratingCount->get(), 4);
     $this->assertEqual($this->product->ratingSum->get(), 22);
     $this->assertEqual($this->product->rating->get(), 5.5);
     // delete last review
     $review->delete();
     $this->product->reload();
     $this->assertEqual($this->product->ratingCount->get(), 2);
     $this->assertEqual($this->product->ratingSum->get(), 10);
     $this->assertEqual($this->product->rating->get(), 5);
     // check rating summaries
     $summary = ProductRatingSummary::getInstance($this->product, $type2);
     $this->assertEqual($summary->rating->get(), 4);
 }
Exemplo n.º 3
0
/**
 * Generates manufacturer page URL
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_manufacturerUrl($params, LiveCartSmarty $smarty)
{
    $manufacturer = $params['data'];
    $params['data'] =& Category::getRootNode()->toArray();
    $params['addFilter'] = new ManufacturerFilter($manufacturer['ID'], $manufacturer['name']);
    return createCategoryUrl($params, $smarty->getApplication());
}
Exemplo n.º 4
0
 public function products()
 {
     $this->setLayout('empty');
     set_time_limit(0);
     $response = new XMLResponse();
     $filter = new ARSelectFilter();
     $filter->setOrder(f('Product.dateCreated'), ARSelectFilter::ORDER_DESC);
     $categoryId = $this->getRequest()->get('id');
     if (preg_match('/^\\d+$/', $categoryId)) {
         $this->shouldBeEnabledFeed('CATEGORY_PRODUCTS');
         $category = Category::getInstanceById($categoryId, Category::LOAD_DATA);
         $filter = new ProductFilter($category, $filter);
     } else {
         $this->shouldBeEnabledFeed('ALL_PRODUCTS');
         $category = Category::getRootNode(true);
         $filter = new ProductFilter($category, $filter);
         $filter->includeSubCategories();
     }
     $feed = new ProductFeed($filter);
     $feed->setFlush();
     $feed->setLimit($this->config->get('NUMBER_OF_PRODUCTS_TO_INCLUDE'));
     $response->set('feed', $feed);
     $response->set('category', $category->toArray());
     return $response;
 }
Exemplo n.º 5
0
 public function testRatingTypes()
 {
     $type = ProductRatingType::getNewInstance(Category::getRootNode());
     $type->save();
     $rating = ProductRating::getNewInstance($this->product, $type);
     $rating->rating->set(6);
     $rating->save();
     $this->product->reload();
     $this->assertEqual($this->product->ratingCount->get(), 1);
     $this->assertEqual($this->product->ratingSum->get(), 6);
     $this->assertEqual($this->product->rating->get(), 6);
     ActiveRecord::clearPool();
     $summary = ProductRatingSummary::getInstance($this->product, $type);
     $summary->reload();
     $this->assertEqual($summary->ratingCount->get(), 1);
     $this->assertEqual($summary->ratingSum->get(), 6);
     $this->assertEqual($summary->rating->get(), 6);
     $type2 = ProductRatingType::getNewInstance(Category::getRootNode());
     $type2->save();
     $rating = ProductRating::getNewInstance($this->product, $type2);
     $rating->rating->set(4);
     $rating->save();
     $this->product->reload();
     $this->assertEqual($this->product->ratingCount->get(), 2);
     $this->assertEqual($this->product->ratingSum->get(), 10);
     $this->assertEqual($this->product->rating->get(), 5);
     ActiveRecord::clearPool();
     $summary = ProductRatingSummary::getInstance($this->product, $type2);
     $summary->reload();
     $this->assertEqual($summary->ratingCount->get(), 1);
     $this->assertEqual($summary->ratingSum->get(), 4);
     $this->assertEqual($summary->rating->get(), 4);
 }
Exemplo n.º 6
0
 /**
  * Products popup
  *
  * @role update
  */
 public function selectProduct()
 {
     $response = new ActionResponse();
     $categoryList = Category::getRootNode()->getDirectChildNodes();
     $categoryList->unshift(Category::getRootNode());
     $response->set("categoryList", $categoryList->toArray());
     return $response;
 }
Exemplo n.º 7
0
 public function setUp()
 {
     parent::setUp();
     $this->root = Category::getRootNode();
     $this->container = Product::getNewInstance($this->root);
     $this->container->type->set(Product::TYPE_BUNDLE);
     $this->container->save();
 }
Exemplo n.º 8
0
 public function testPositions()
 {
     $type1 = ProductRatingType::getNewInstance(Category::getRootNode());
     $type1->save();
     $type2 = ProductRatingType::getNewInstance(Category::getRootNode());
     $type2->save();
     $this->assertEqual($type1->position->get(), 1);
     $this->assertEqual($type2->position->get(), 2);
 }
Exemplo n.º 9
0
 public function testContaining()
 {
     $root = Category::getRootNode();
     $list = ProductList::getNewInstance($root);
     $list->save();
     $product = Product::getNewInstance($root);
     $product->save();
     $list->addProduct($product);
     $another = Product::getNewInstance($root);
     $another->save();
     $this->assertTrue($list->contains($product));
     $this->assertFalse($list->contains($another));
 }
Exemplo n.º 10
0
 public function setUp()
 {
     parent::setUp();
     $this->product = Product::getNewInstance(Category::getRootNode(), 'test');
     $this->product->save();
     $this->option = ProductOption::getNewInstance($this->product);
     $this->option->type->set(ProductOption::TYPE_SELECT);
     $this->option->save();
     for ($k = 0; $k <= 1; $k++) {
         $choice = ProductOptionChoice::getNewInstance($this->option);
         $choice->priceDiff->set(10 + $k);
         $choice->save();
         $this->choices[] = $choice;
     }
 }
Exemplo n.º 11
0
 public function setUp()
 {
     parent::setUp();
     Category::recalculateProductsCount();
     $this->root = Category::getNewInstance(Category::getRootNode());
     $this->root->save();
     for ($k = 1; $k <= 2; $k++) {
         $cat = Category::getNewInstance($this->root);
         $cat->save();
         $this->categories[$k] = $cat;
     }
     $this->product = Product::getNewInstance($this->categories[1]);
     $this->product->save();
     $this->secondCategory = ProductCategory::getNewInstance($this->product, $this->categories[2]);
     $this->secondCategory->save();
 }
Exemplo n.º 12
0
 public function testDelete()
 {
     $category = Category::getNewInstance(Category::getRootNode());
     $category->save();
     $field = SpecField::getNewInstance($category, SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_SIMPLE);
     $field->handle->set('randomhandle');
     $field->save();
     $this->request->set('id', $field->getID());
     $response = $this->controller->delete();
     $this->assertIsA($response, 'JSONResponse');
     $value = $response->getValue();
     $this->assertEqual($value['status'], 'success');
     // already deleted
     $response = $this->controller->delete();
     $value = $response->getValue();
     $this->assertEqual($value['status'], 'failure');
 }
Exemplo n.º 13
0
 private function createOrder()
 {
     $user = User::getNewInstance('*****@*****.**');
     $user->save();
     $currency = Currency::getInstanceByID('USD');
     $product = Product::getNewInstance(Category::getRootNode());
     $product->isEnabled->set(true);
     $product->stockCount->set(100);
     $product->setPrice($currency, 100);
     $product->setValueByLang('name', null, 'Test name');
     $product->setValueByLang('shortDescription', null, 'Really short description');
     $product->save();
     $order = CustomerOrder::getNewInstance($user);
     $order->addProduct($product, 1);
     $order->save();
     return $order;
 }
Exemplo n.º 14
0
 public function testRatingTypes()
 {
     $types = array();
     for ($k = 1; $k <= 3; $k++) {
         $type = ProductRatingType::getNewInstance(Category::getRootNode());
         $type->save();
         $types[$k] = $type;
         $this->request->set('rating_' . $type->getID(), $k);
     }
     $this->controller->rate();
     $this->product->reload();
     $response = $this->controller->index();
     $ratings = $response->get('rating');
     $this->assertEqual(count($ratings), 3);
     foreach ($ratings as $key => $rating) {
         $this->assertEqual($key + 1, $rating['rating']);
     }
 }
Exemplo n.º 15
0
 public function export()
 {
     $module = $this->request->get('module');
     $enabledFeeds = $this->config->get('ENABLED_FEEDS');
     if (!isset($enabledFeeds[$module]) || $this->request->get('key') != $this->config->get('FEED_KEY')) {
         return;
     }
     $this->setLayout('empty');
     set_time_limit(0);
     $cat = Category::getRootNode(true);
     $filter = new ProductFilter($cat, new ARSelectFilter());
     $filter->includeSubCategories();
     $feed = new ProductFeed($filter);
     $feed->setFlush();
     $response = new XMLResponse();
     $response->set('feed', $feed);
     $response->set('tpl', 'xml/feed/' . $module . '.tpl');
     return $response;
 }
Exemplo n.º 16
0
 public function index()
 {
     $this->loadLanguageFile('backend/abstract/ActiveGridQuickEdit');
     $this->updateApplicationUri();
     // order stats
     $conditions = array('last' => new EqualsOrMoreCond(new ARFieldHandle('CustomerOrder', 'dateCompleted'), time() - 86400), 'new' => new IsNullCond(new ARFieldHandle('CustomerOrder', 'status')), 'processing' => new EqualsCond(new ARFieldHandle('CustomerOrder', 'status'), CustomerOrder::STATUS_PROCESSING), 'total' => new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
     foreach ($conditions as $key => $cond) {
         $f = new ARSelectFilter($cond);
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isCancelled'), false));
         $orderCount[$key] = ActiveRecordModel::getRecordCount('CustomerOrder', $f);
     }
     // messages
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('OrderNote', 'isAdmin'), 0));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderNote', 'isRead'), 0));
     $orderCount['messages'] = ActiveRecordModel::getRecordCount('OrderNote', $f);
     // inventory stats
     $lowStock = new EqualsOrLessCond(new ARFieldHandle('Product', 'stockCount'), $this->config->get('LOW_STOCK'));
     $lowStock->addAnd(new MoreThanCond(new ARFieldHandle('Product', 'stockCount'), 0));
     $conditions = array('lowStock' => $lowStock, 'outOfStock' => new EqualsOrLessCond(new ARFieldHandle('Product', 'stockCount'), 0));
     foreach ($conditions as $key => $cond) {
         $cond->addAnd(new EqualsCond(new ARFieldHandle('Product', 'isEnabled'), true));
         $inventoryCount[$key] = ActiveRecordModel::getRecordCount('Product', new ARSelectFilter($cond));
     }
     // overall stats
     $rootCat = Category::getRootNode();
     $rootCat->load();
     $response = new ActionResponse();
     $response->set('orderCount', $orderCount);
     $response->set('inventoryCount', $inventoryCount);
     $response->set('rootCat', $rootCat->toArray());
     $response->set('thisMonth', date('m'));
     $response->set('lastMonth', date('Y-m', strtotime(date('m') . '/15 -1 month')));
     $response->set('ordersLast24', $this->getOrderCount('-24 hours', 'now'));
     $response->set('ordersThisWeek', $this->getOrderCount('w:Monday', 'now'));
     $response->set('ordersThisMonth', $this->getOrderCount(date('m') . '/1', 'now'));
     $response->set('ordersLastMonth', $this->getOrderCount($response->get('lastMonth') . '-1', date('m') . '/1'));
     $response->set('lastOrders', $this->getLastOrders());
     return $response;
 }
Exemplo n.º 17
0
 public function getNextSpecField()
 {
     if (is_null($this->specFieldSql)) {
         $join = $langs = array();
         foreach ($this->languages as $id => $code) {
             list($join[], $langs[]) = $this->joinAttributeFields($id, $code);
         }
         // get all categories
         $this->specFieldSql = 'SELECT ' . $this->getTablePrefix() . 'extra_fields.* ' . ($langs ? ',' : '') . implode(', ', $langs) . ' FROM ' . $this->getTablePrefix() . 'extra_fields ' . implode(' ', $join) . ' ORDER BY orderby ASC';
     }
     if (!($data = $this->loadRecord($this->specFieldSql))) {
         return null;
     }
     $this->attributes[] = $data;
     $rec = SpecField::getNewInstance(Category::getRootNode(), SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_SIMPLE);
     $rec->setID($data['fieldid']);
     $rec->handle->set($data['service_name']);
     $rec->setValueByLang('name', $this->defLang, $data['field']);
     $rec->isDisplayed->set(true);
     foreach ($this->languages as $code => $id) {
         $rec->setValueByLang('name', $code, $data['fieldname_' . $code]);
     }
     return $rec;
 }
Exemplo n.º 18
0
 protected function getCategory()
 {
     $cat = Category::getRootNode();
     $cat->load();
     return $cat;
 }
Exemplo n.º 19
0
 public static function getDefaultRatingType()
 {
     return self::getNewInstance(Category::getRootNode());
 }
Exemplo n.º 20
0
 public function testTextRulesSpecField()
 {
     $field = SpecField::getNewInstance(Category::getRootNode(), SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_ADVANCED);
     $field->save();
     $product = Product::getNewInstance($this->categories['1.2.1']);
     $product->sku->set('testing');
     $product->save();
     $product->setAttributeValueByLang($field, $this->getApplication()->getDefaultLanguageCode(), 'Attribute value');
     $product->save();
     $rule = ClonedStoreRule::getNewInstance($this->stores[0], ClonedStoreRule::TYPE_TEXT);
     $rule->field->set('specField.' . $field->getID());
     $rule->find->set('value');
     $rule->repl->set('replaced');
     $rule->save();
     $updater = $this->getUpdater();
     $updater->syncAll();
     $row = ActiveRecord::getDataBySQL('SELECT * FROM ' . $updater->getImportDatabase() . '.SpecificationStringValue WHERE productID=' . $product->getID());
     $row = array_shift($row);
     $name = unserialize($row['value']);
     $this->assertEqual($name[$this->getApplication()->getDefaultLanguageCode()], 'Attribute replaced');
 }
Exemplo n.º 21
0
 public function testChildProduct()
 {
     $this->product->setPrice($this->usd, 20);
     $this->product->shippingWeight->set(200);
     $this->product->save();
     $child = $this->product->createChildProduct();
     $root = Category::getRootNode();
     $root->reload();
     $productCount = $root->totalProductCount->get();
     // in array representation, parent product data is used where own data is not set
     $array = $child->toArray();
     $this->assertEquals($array['name_en'], $this->product->getValueByLang('name', 'en'));
     // auto-generated SKU is based on parent SKU
     $child->save();
     $this->assertEquals($child->sku->get(), $this->product->sku->get() . '-1');
     // category counters should not change
     $root->reload();
     $this->assertEquals($root->totalProductCount->get(), $productCount);
     // parent product price used if not defined
     $this->assertEquals($child->getPrice($this->usd), $this->product->getPrice($this->usd));
     // parent shipping weight used if not defined
     $this->assertEquals($child->getShippingWeight(), $this->product->getShippingWeight());
     // add/substract parent prices/shipping weights
     $child->setChildSetting('test', 'value');
     $this->assertEquals($child->getChildSetting('test'), 'value');
     // prices
     $child->setChildSetting('price', Product::CHILD_ADD);
     $child->setPrice($this->usd, 5);
     $this->assertEquals(20, $this->product->getPrice($this->usd));
     $this->assertEquals($child->getPrice($this->usd), $this->product->getPrice($this->usd) + 5);
     $child->setChildSetting('price', Product::CHILD_SUBSTRACT);
     $this->assertEquals($child->getPrice($this->usd), $this->product->getPrice($this->usd) - 5);
     $child->setChildSetting('price', Product::CHILD_OVERRIDE);
     $this->assertEquals($child->getPrice($this->usd), 5);
     // shipping weight
     $child->setChildSetting('weight', Product::CHILD_ADD);
     $child->shippingWeight->set(5);
     $this->assertEquals(200, $this->product->getShippingWeight());
     $this->assertEquals($child->getShippingWeight(), $this->product->getShippingWeight() + 5);
     $child->setChildSetting('weight', Product::CHILD_SUBSTRACT);
     $this->assertEquals($child->getShippingWeight(), $this->product->getShippingWeight() - 5);
     $child->setChildSetting('weight', Product::CHILD_OVERRIDE);
     $this->assertEquals($child->getShippingWeight(), 5);
 }
Exemplo n.º 22
0
 public function getNextCategory()
 {
     if (is_null($this->categoryMap)) {
         $join = $langs = array();
         foreach ($this->languages as $id => $code) {
             list($join[], $langs[]) = $this->joinCategoryFields($id, $code);
         }
         // get all categories
         $q = 'SELECT *,' . $this->getTablePrefix() . 'categories.categories_id AS categories_id,' . implode(', ', $langs) . ' FROM ' . $this->getTablePrefix() . 'categories ' . implode(' ', $join) . ' ORDER BY sort_order ASC';
         foreach ($this->getDataBySQL($q) as $category) {
             $this->categoryMap[$category['categories_id']] = $category;
         }
         // get level for each category
         foreach ($this->categoryMap as $id => &$category) {
             $level = 0;
             while ($id != 0 && $level < 100) {
                 $level++;
                 if (isset($this->categoryMap[$id]['parent_id'])) {
                     $id = $this->categoryMap[$id]['parent_id'];
                 } else {
                     if ($this->categoryMap[$id]['parent_id'] != 0) {
                         unset($this->categoryMap[$id]);
                         $level = 101;
                     }
                 }
             }
             // circular reference
             if ($level >= 100) {
                 unset($this->categoryMap[$category['categories_id']]);
             } else {
                 $category['level'] = $level;
             }
         }
         usort($this->categoryMap, array($this, 'sortCategories'));
     }
     // root level categories first
     if ($data = array_shift($this->categoryMap)) {
         $parentNode = 0 == $data['parent_id'] ? Category::getRootNode() : Category::getInstanceById($this->getRealId('Category', $data['parent_id']));
         $rec = Category::getNewInstance($parentNode);
     } else {
         return null;
     }
     $rec->setID($data['categories_id']);
     $rec->isEnabled->set(true);
     foreach ($this->languages as $code) {
         $rec->setValueByLang('name', $code, $data['name_' . $code]);
     }
     //product image
     if ($data['categories_image']) {
         $this->importCategoryImage($rec, $this->path . '/images/' . $data['categories_image']);
     }
     $rec->rawData = $data;
     return $rec;
 }
Exemplo n.º 23
0
 public function __construct(LiveCart $application)
 {
     $this->root = Category::getRootNode();
     parent::__construct($application, 'Category', array());
 }
Exemplo n.º 24
0
 /**
  *	@todo: doesn't work
  */
 public function testAdditionalCategories()
 {
     $customCategory = Category::getNewInstance(Category::getRootNode());
     $customCategory->save();
     $product = $this->product1;
     $this->order->addProduct($product, 1, true);
     $this->order->save();
     $condition = DiscountCondition::getNewInstance();
     $condition->isEnabled->set(true);
     $condition->conditionClass->set('RuleConditionContainsProduct');
     $condition->save();
     DiscountConditionRecord::getNewInstance($condition, $customCategory)->save();
     $this->assertEquals(0, count($this->order->getDiscountConditions(true)));
     ProductCategory::getNewInstance($product, $customCategory)->save();
     $condition->loadAll();
     //$this->assertEquals(1, count($this->order->getDiscountConditions(true)));
 }
Exemplo n.º 25
0
 private function getRoot(CsvImportProfile $profile)
 {
     $id = $profile->getParam('category');
     $cat = $id ? Category::getInstanceByID($id, true) : Category::getRootNode();
     return $cat;
 }
Exemplo n.º 26
0
 protected function boxFilterBlock($includeAppliedFilters = true)
 {
     $filterStyle = $this->config->get('FILTER_STYLE');
     if ('FILTER_STYLE_CHECKBOXES' == $filterStyle) {
         $includeAppliedFilters = false;
     }
     $count = $this->getFilterCounts($includeAppliedFilters);
     $filterGroups = $count['groups'];
     // remove empty filter groups
     $maxCriteria = $this->config->get('MAX_FILTER_CRITERIA_COUNT');
     $showAll = $this->request->get('showAll');
     $url = $this->router->createUrlFromRoute($this->router->getRequestedRoute(), true);
     $url = $this->router->addQueryParams($url);
     foreach ((array) $filterGroups as $key => $grp) {
         foreach ((array) $grp['filters'] as $k => $f) {
             if (!$f['count']) {
                 unset($filterGroups[$key]['filters'][$k]);
             }
         }
         if (empty($grp['filters'])) {
             unset($filterGroups[$key]);
         } else {
             if ($showAll != $grp['ID'] && count($grp['filters']) > $maxCriteria && $maxCriteria > 0) {
                 $filterGroups[$key]['more'] = $this->router->setUrlQueryParam($url, 'showAll', $grp['ID']);
             }
         }
     }
     $response = new BlockResponse();
     // filter by manufacturers
     $manFilters = $count['manufacturers'];
     if (count($manFilters) > $maxCriteria && $showAll != 'brand' && $maxCriteria > 0) {
         $response->set('allManufacturers', $this->router->setUrlQueryParam($url, 'showAll', 'brand'));
     }
     if (!$this->getCategory()) {
         $this->category = Category::getRootNode();
         $this->category->load();
     }
     $priceFilters = $count['prices'];
     // hide price filters from side menu if a price filter is applied
     if ($includeAppliedFilters) {
         foreach ($this->filters as $filter) {
             if ($filter instanceof PriceFilter) {
                 $priceFilters = array();
             }
         }
     }
     // index page filters
     if ($this->getCategory()->isRoot()) {
         if (!$this->config->get('INDEX_MAN_FILTERS')) {
             $manFilters = array();
         }
         if (!$this->config->get('INDEX_PRICE_FILTERS')) {
             $priceFilters = array();
         }
     } else {
         if (!$this->hasProducts) {
             if (!$this->config->get('DISPLAY_CAT_MAN_FILTERS')) {
                 $manFilters = array();
             }
             if (!$this->config->get('DISPLAY_CAT_PRICE_FILTERS')) {
                 $priceFilters = array();
             }
         }
     }
     if ($this->config->get('ENABLE_MAN_FILTERS') && count($manFilters) > 1) {
         $response->set('manGroup', array('filters' => $manFilters));
     }
     if ($this->config->get('ENABLE_PRICE_FILTERS') && count($count['prices']) > 1) {
         foreach ($priceFilters as $key => $filter) {
             if (!$filter['count']) {
                 unset($priceFilters[$key]);
             }
         }
         $response->set('priceGroup', array('filters' => $priceFilters));
     }
     $appliedFilterArray = $this->getAppliedFilterArray();
     $response->set('filters', $appliedFilterArray);
     if ('FILTER_STYLE_CHECKBOXES' == $filterStyle) {
         $IDs = array();
         foreach ($appliedFilterArray as $item) {
             $IDs[] = $item['ID'];
         }
         $response->set('filtersIDs', $IDs);
     }
     $response->set('category', $this->getCategory()->toArray());
     $response->set('groups', $filterGroups);
     return $response;
 }
Exemplo n.º 27
0
 private function getSelectFilter($class)
 {
     if ('Product' == $class) {
         $cat = Category::getRootNode();
         $f = $cat->getProductFilter(new ARSelectFilter());
         $f->mergeCondition($cat->getProductCondition(true));
         $f->joinTable('Category', 'Product', 'ID', 'categoryID');
         return $f;
     }
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle($class, 'ID'));
     if ('StaticPage' != $class) {
         $f->setCondition(new EqualsCond(new ARFieldHandle($class, 'isEnabled'), true));
     }
     if ('Category' == $class) {
         $f->mergeCondition(new NotEqualsCond(new ARFieldHandle($class, 'ID'), Category::ROOT_ID));
     }
     return $f;
 }
Exemplo n.º 28
0
 public function getApiFields($type)
 {
     $this->loadLanguageFile('Api');
     $this->loadLanguageFile('backend/Settings/API');
     $this->loadLanguageFile('backend/CsvImport');
     $this->loadLanguageFile('backend/UserGroup');
     $c = new ClonedApiController($this->application);
     $doc = $c->getDocInfo();
     $classes = array_diff_key($doc, array_flip(array('CustomerOrderApi', 'UserApi')));
     $fields = array();
     $ignoredFields = array('Category.lft', 'Product.type', 'Product.rating', 'Product.shippingSurchargeAmount', 'Product.minimumQuantity', 'Product.shippingWeight', 'Product.fractionalStep');
     foreach ($classes as $model => $data) {
         $inst = $data['inst'];
         $this->loadLanguageFile('backend/' . $inst->getClassName());
         $this->request->set(ApiReader::API_PARSER_CLASS_NAME, 'Xml' . get_class($inst) . 'Reader');
         $inst->loadRequest(false);
         $searchFields = array();
         $e = error_reporting();
         error_reporting(E_STRICT);
         foreach ((array) $inst->getParser()->getValidSearchFields($inst->getClassName()) as $key => $field) {
             $fieldName = $field[0]->toString();
             $translation = $this->translate($fieldName);
             if ($type == ClonedStoreRule::TYPE_TEXT) {
                 list($foo, $dbField) = explode('.', $fieldName);
                 if (in_array($dbField, array('position')) || in_array($fieldName, $ignoredFields) || 'ProductPriceApi' == $model || $translation == $fieldName || substr($key, -2) == 'ID' || substr($translation, 0, 3) == 'Is ' || substr($dbField, 0, 2) == 'is' || substr($dbField, 0, 4) == 'date' || strpos($key, 'Count')) {
                     continue;
                 }
             }
             $searchFields[$fieldName] = array('field' => $key);
             if ($translation != $fieldName) {
                 $searchFields[$fieldName]['descr'] = $translation;
             }
             $searchFields[$fieldName]['descr'] .= ' (%' . $dbField . '%)';
         }
         error_reporting($e);
         if ('ProductApi' == $model) {
             $searchFields['Product.custom'] = array('field' => 'Product.custom', 'descr' => 'Custom variation field (%custom%)');
             foreach (Category::getRootNode()->getRelatedRecordSetArray('SpecField', select(eq(f('SpecField.dataType'), SpecField::DATATYPE_TEXT))) as $field) {
                 $f = 'specField.' . $field['ID'];
                 $searchFields[$f] = array('field' => $f, 'descr' => $field['name_lang'] . ' (%field_' . $field['handle'] . '%)');
             }
         }
         if ($searchFields) {
             $fields[$model] = $searchFields;
         }
         /*
         var_dump($searchFields);
         continue;
         
         if (!$importer)
         {
         		continue;
         }
         
         
         $createFields = array();
         $className = $inst->getClassName();
         foreach ($importer->getFields() as $groupName => $fields)
         {
         	$apiFields = array();
         	foreach ($fields as $field => $translation)
         	{
         		list($class, $column) = explode('.', $field);
         		if ($class == $className)
         		{
         			$field = $column;
         		}
         
         		$field = str_replace('.', '_', $field);
         		$apiFields[$field] = $translation;
         	}
         
         	$createFields[$this->translate($groupName)] = $apiFields;
         }
         
         var_dump($createFields);
         */
     }
     return $fields;
 }
Exemplo n.º 29
0
 public function productSelectPopup()
 {
     $categoryList = Category::getRootNode()->getDirectChildNodes();
     $categoryList->unshift(Category::getRootNode());
     return new ActionResponse('categoryList', $categoryList->toArray());
 }
Exemplo n.º 30
0
 public function testTaxClassesWithDefaultZoneAndMultipleTaxes()
 {
     $order = CustomerOrder::getNewInstance($this->user);
     $zone = $order->getDeliveryZone();
     $this->assertTrue($zone->isDefault());
     // default tax level
     TaxRate::getNewInstance($zone, $this->tax, 10)->save();
     $newTax = Tax::getNewInstance('test');
     $newTax->save();
     // diferent tax rate for books
     $books = TaxClass::getNewInstance('Books');
     $books->save();
     $booksRate = TaxRate::getNewInstance($zone, $this->tax, 5);
     $booksRate->taxClass->set($books);
     $booksRate->save();
     $booksRate = TaxRate::getNewInstance($zone, $newTax, 20);
     $booksRate->taxClass->set($books);
     $booksRate->save();
     // price = 100
     $cd = $this->product;
     $book = Product::getNewInstance(Category::getRootNode());
     $book->setPrice('USD', 50);
     $book->isEnabled->set(true);
     $book->taxClass->set($books);
     $book->save();
     $order->addProduct($cd, 1, true);
     $order->addProduct($book, 1, true);
     $order->currency->set($this->currency);
     $order->save();
     $this->assertEqual($order->getTaxAmount(), 19.41);
     $this->assertEqual($order->getTotal(true), 150);
     $service = ShippingService::getNewInstance($order->getDeliveryZone(), 'def', ShippingService::SUBTOTAL_BASED);
     $service->save();
     $shippingRate = ShippingRate::getNewInstance($service, 0, 10000000);
     $shippingRate->flatCharge->set(100);
     $shippingRate->save();
     $shipment = $order->getShipments()->get(0);
     $rates = $order->getDeliveryZone()->getShippingRates($shipment);
     $shipment->setAvailableRates($rates);
     $shipment->setRateId($rates->get(0)->getServiceID());
     $shipment->save();
     $this->assertEqual($order->getTotal(true), 250);
     $this->assertEqual((string) $order->getTaxAmount(), (string) 28.5);
 }