当前位置: 首页>>代码示例>>PHP>>正文


PHP Category::getNewInstance方法代码示例

本文整理汇总了PHP中Category::getNewInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::getNewInstance方法的具体用法?PHP Category::getNewInstance怎么用?PHP Category::getNewInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Category的用法示例。


在下文中一共展示了Category::getNewInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createCategory

 private function createCategory(Category $parent, $name)
 {
     $cat = Category::getNewInstance($parent);
     $cat->setValueByLang('name', null, $name);
     $cat->isEnabled->set(true);
     $cat->save();
     return $cat;
 }
开发者ID:saiber,项目名称:www,代码行数:8,代码来源:TestStoreCloning.php

示例2: create

 /**
  * Creates a new category record
  *
  * @role !category.create
  *
  * @return ActionRedirectResponse
  */
 public function create()
 {
     $parent = Category::getRequestInstance($this->request, 'parent');
     $categoryNode = Category::getNewInstance($parent);
     $categoryNode->loadRequestModel($this->request);
     $categoryNode->save();
     return new JSONResponse($this->getCategoryJson($categoryNode->toArray()), 'success', $this->translate('_new_category_was_successfully_created'));
 }
开发者ID:saiber,项目名称:livecart,代码行数:15,代码来源:CategoryController.php

示例3: create

 /**
  * Creates a new category record
  *
  * @role !category.create
  *
  * @return ActionRedirectResponse
  */
 public function create()
 {
     $parent = Category::getInstanceByID((int) $this->request->get("id"));
     $categoryNode = Category::getNewInstance($parent);
     $categoryNode->setValueByLang("name", $this->application->getDefaultLanguageCode(), 'dump');
     $categoryNode->save();
     $categoryNode->setValueByLang("name", $this->application->getDefaultLanguageCode(), $this->translate("_new_category") . " " . $categoryNode->getID());
     $categoryNode->save();
     return new JSONResponse($categoryNode->toArray(), 'success');
 }
开发者ID:GregerA,项目名称:livecart,代码行数:17,代码来源:CategoryController.php

示例4: create

 public function create()
 {
     $parser = $this->getParser();
     $request = $this->application->getRequest();
     $parser->loadDataInRequest($request);
     $parentId = $request->get(Category::PARENT_NODE_FIELD_NAME);
     $parentCategory = $parentId > 0 ? $this->_getCategoryById($parentId, true) : $this->root;
     $category = Category::getNewInstance($parentCategory);
     $category->loadRequestData($request);
     $category->save();
     return $this->statusResponse($category->getID(), 'created');
 }
开发者ID:saiber,项目名称:www,代码行数:12,代码来源:CategoryApi.php

示例5: setUp

 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();
 }
开发者ID:saiber,项目名称:livecart,代码行数:16,代码来源:ProductCategoryTest.php

示例6: testProductRatingTypes

 public function testProductRatingTypes()
 {
     $subCategory = Category::getNewInstance(Category::getRootNode());
     $subCategory->save();
     $product = Product::getNewInstance($subCategory, 'test');
     $product->save();
     $rootType = ProductRatingType::getNewInstance(Category::getRootNode());
     $rootType->save();
     $subType = ProductRatingType::getNewInstance($subCategory);
     $subType->save();
     $types = ProductRatingType::getProductRatingTypes($product);
     $this->assertEqual($types->size(), 2);
     // parent category types should go first
     $this->assertSame($types->get(0), $rootType);
     $this->assertSame($types->get(1), $subType);
 }
开发者ID:saiber,项目名称:livecart,代码行数:16,代码来源:ProductRatingTypeTest.php

示例7: _testStringSerialize

 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);
 }
开发者ID:saiber,项目名称:livecart,代码行数:16,代码来源:MultiLingualObjectTest.php

示例8: testDelete

 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');
 }
开发者ID:saiber,项目名称:livecart,代码行数:17,代码来源:SpecFieldControllerTest.php

示例9: getNextCategory

 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
         $sql = 'SELECT ' . $this->getTablePrefix() . 'categories.* ' . ($langs ? ',' : '') . implode(', ', $langs) . ' FROM ' . $this->getTablePrefix() . 'categories ' . implode(' ', $join) . ' ORDER BY order_by ASC';
         foreach ($this->getDataBySQL($sql) as $category) {
             $this->categoryMap[$category['categoryid']] = $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]['parentid'])) {
                     $id = $this->categoryMap[$id]['parentid'];
                 } else {
                     if ($this->categoryMap[$id]['parentid'] != 0) {
                         unset($this->categoryMap[$id]);
                         $level = 101;
                     }
                 }
             }
             // circular reference
             if ($level >= 100) {
                 unset($this->categoryMap[$category['categoryid']]);
             } else {
                 $category['level'] = $level;
             }
         }
         usort($this->categoryMap, array($this, 'sortCategories'));
     }
     // root level categories first
     if ($data = array_shift($this->categoryMap)) {
         $parentNode = 0 == $data['parentid'] ? Category::getRootNode() : Category::getInstanceById($this->getRealId('Category', $data['parentid']));
         $rec = Category::getNewInstance($parentNode);
     } else {
         return null;
     }
     $rec->setID($data['categoryid']);
     $rec->isEnabled->set('Y' == $data['avail']);
     $rec->keywords->set($data['meta_keywords']);
     $rec->setValueByLang('name', $this->defLang, $data['category']);
     $rec->setValueByLang('description', $this->defLang, $data['description']);
     foreach ($this->languages as $code => $id) {
         $rec->setValueByLang('name', $code, $data['category_' . $code]);
         $rec->setValueByLang('description', $code, $data['description_' . $code]);
     }
     //images
     $images = $this->getDataBySQL('SELECT * FROM ' . $this->getTablePrefix() . 'images_c WHERE id=' . $data['categoryid'] . ' ORDER BY orderby ASC');
     foreach ($images as $image) {
         $this->importCategoryImage($rec, $this->path . '/' . $image['image_path']);
     }
     $rec->rawData = $data;
     return $rec;
 }
开发者ID:saiber,项目名称:livecart,代码行数:59,代码来源:XCartImport.php

示例10: getNextCategory

 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;
 }
开发者ID:saiber,项目名称:livecart,代码行数:54,代码来源:OsCommerceImport.php

示例11: getCategoryByPath

 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;
 }
开发者ID:GregerA,项目名称:livecart,代码行数:27,代码来源:ProductImport.php

示例12: testActiveProductCountWhenChangingCategoryAvailability

 public function testActiveProductCountWhenChangingCategoryAvailability()
 {
     $this->root->reload();
     $rootActiveProductCount = $this->root->activeProductCount->get();
     $rootAotalProductCount = $this->root->totalProductCount->get();
     $rootAvailableProductCount = $this->root->availableProductCount->get();
     $subCategory = Category::getNewInstance($this->root);
     $subCategory->setValueByLang("name", 'en', "New Category 1");
     $subCategory->isEnabled->set(false);
     $subCategory->activeProductCount->set(1);
     $subCategory->totalProductCount->set(1);
     $subCategory->availableProductCount->set(1);
     $subCategory->save();
     $this->root->reload();
     $this->assertEqual($rootActiveProductCount, $this->root->activeProductCount->get());
     $subCategory->isEnabled->set(true);
     $subCategory->save();
     $this->root->reload();
     $this->assertEqual($rootActiveProductCount + 1, $this->root->activeProductCount->get());
 }
开发者ID:saiber,项目名称:livecart,代码行数:20,代码来源:CategoryTest.php

示例13: testCategoryCountsWhenEnabledProductWithNoStockIsAdded

 /**
  *  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());
 }
开发者ID:saiber,项目名称:livecart,代码行数:22,代码来源:ProductTest.php

示例14: testAdditionalCategories

 /**
  *	@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)));
 }
开发者ID:saiber,项目名称:livecart,代码行数:20,代码来源:DiscountConditionTest.php

示例15: testDiscountByAdditionalCategories

 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));
 }
开发者ID:saiber,项目名称:livecart,代码行数:40,代码来源:OrderTest.php


注:本文中的Category::getNewInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。