當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ProductCategory::create方法代碼示例

本文整理匯總了PHP中ProductCategory::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP ProductCategory::create方法的具體用法?PHP ProductCategory::create怎麽用?PHP ProductCategory::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ProductCategory的用法示例。


在下文中一共展示了ProductCategory::create方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     Product::create(['name' => 'Test Product', 'slug' => 'test-product', 'price' => 100, 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent rhoncus, turpis ac imperdiet dapibus, leo orci gravida neque, in malesuada elit libero eu sapien. Mauris sed sapien id sapien bibendum luctus et eu massa. Nulla egestas interdum magna non dignissim. Sed a laoreet purus, non rutrum augue. Proin laoreet eros nec elit mattis euismod. Aliquam facilisis, lacus blandit iaculis accumsan, leo quam sagittis nisi, non dapibus arcu libero efficitur turpis. In fringilla est nec sapien tempus suscipit. Suspendisse eget justo risus.']);
     Product::create(['name' => 'Uncategorized Product', 'slug' => 'uncategorized-product', 'price' => 200, 'description' => 'This product has no category.']);
     Category::create(['name' => 'Test Category', 'slug' => 'test-category']);
     ProductCategory::create(['product_id' => 1, 'category_id' => 1]);
 }
開發者ID:joeyemery,項目名稱:ecommerce,代碼行數:13,代碼來源:DatabaseSeeder.php

示例2: get_current_category

 /**
  * Find the current category via its URL
  *
  * @return ProductCategory
  *
  */
 public static function get_current_category()
 {
     $segment = Controller::curr()->request->param('URLSegment');
     $return = null;
     if ($segment) {
         $return = ProductCategory::get()->filter('URLSegment', $segment)->first();
     }
     if (!$return) {
         $return = ProductCategory::create();
     }
     return $return;
 }
開發者ID:helpfulrobot,項目名稱:i-lateral-silverstripe-commerce,代碼行數:18,代碼來源:Catalogue_Controller.php

示例3: createProduct

 /**
  * create product
  *
  * @param string $sku			The sku of product
  * @param string $name			The name of product
  * @param array $categoryPaths	The category paths of product (e.g. $categories = array(array('cate2', 'cate3'), array('cate4', 'cate5', 'cate6'));
  * @param string $mageProductId //TODO
  * @param string $isFromB2B
  * @param string $shortDescr
  * @param string $fullDescr
  * @param string $brandName
  *
  * @throws Exception
  * @return string
  * @soapmethod
  */
 public function createProduct($sku, $name, $categoryPaths = array(), $mageProductId = '', $isFromB2B = false, $shortDescr = '', $fullDescr = '', $brandName = '')
 {
     $response = $this->_getResponse(UDate::now());
     try {
         Dao::beginTransaction();
         Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
         //TODO
         if (Product::getBySku(trim($sku)) instanceof Product) {
             throw new Exception('sku "' . $sku . '" already exists');
         }
         $categories = array();
         if (is_array($categoryPaths)) {
             foreach ($categoryPaths as $categoryPath) {
                 $parentCategory = null;
                 foreach ($categoryPath as $categoryName) {
                     if (count($i = ProductCategory::getAllByCriteria('name = ?', array(trim($categoryName)), true, 1, 1)) > 0) {
                         $categories[$i[0]->getId()] = $category = $i[0];
                     } else {
                         $category = ProductCategory::create(trim($categoryName), trim($categoryName), $parentCategory);
                         $categories[$category->getId()] = $category;
                     }
                     $parentCategory = $category;
                 }
             }
         }
         // create product
         $product = Product::create(trim($sku), trim($name));
         // TODO
         foreach ($categories as $category) {
             $product->addCategory($category);
         }
         $response['status'] = self::RESULT_CODE_SUCC;
         $this->addCData('product', json_encode($product->getJson()), $response);
         Dao::commitTransaction();
     } catch (Exception $e) {
         Dao::rollbackTransaction();
         $response['status'] = self::RESULT_CODE_FAIL;
         $this->addCData('error', $e->getMessage(), $response);
     }
     return trim($response->asXML());
 }
開發者ID:larryu,項目名稱:magento-b2b,代碼行數:57,代碼來源:APIProduct.php

示例4: injectProductCategory

 public function injectProductCategory()
 {
     $validator = Validator::make($data = Input::all(), ProductCategory::$rules);
     if ($validator->fails()) {
         return 'failt';
     }
     ProductCategory::create($data);
     return 'worked';
 }
開發者ID:NocturnalWare,項目名稱:managedotband,代碼行數:9,代碼來源:ProductsController.php

示例5: setParent

 public function setParent(&$obj, $val, $record)
 {
     $title = strtolower(Convert::raw2sql($val));
     if ($title) {
         if ($parentpage = DataObject::get_one('ProductCategory', "LOWER(\"Title\") = '{$title}'", '"Created" DESC')) {
             // find or create parent category, if provided
             $obj->ParentID = $parentpage->ID;
             $obj->write();
             $obj->writeToStage('Stage');
             $obj->publish('Stage', 'Live');
             //TODO: otherwise assign it to the first prodcut group found
         } elseif (self::$createnewproductgroups) {
             //create parent product group
             $pg = ProductCategory::create();
             $pg->setTitle($title);
             $pg->ParentID = self::$parentpageid ? $parentpageid : 0;
             $pg->writeToStage('Stage');
             $pg->publish('Stage', 'Live');
             $obj->ParentID = $pg->ID;
             $obj->write();
             $obj->writeToStage('Stage');
             $obj->publish('Stage', 'Live');
         }
     }
 }
開發者ID:burnbright,項目名稱:silverstripe-shop,代碼行數:25,代碼來源:ProductBulkLoader.php

示例6: ProductCategory

<?php

require_once '../productCategory.php';
//from root/model/
$function = $_POST['function'];
$parent = @$_POST['parent'];
$parentIndex = @$_POST['parentIndex'];
$name = @$_POST['name'];
if ($function == "postNewEntry") {
    $category = new ProductCategory($name, $parent, $parentIndex);
    $category->create();
    echo "{$category->index}";
    //echo "obtainded info : $name , $parent , $parentIndex";
    //echo "$category->index is index, $category->parent";
}
if ($function == "createNewColor") {
    $colorName = $name;
    productCategory::createNewColor($colorName);
    echo productCategory::getLastColorIndex();
}
開發者ID:n-sakib,項目名稱:juierp,代碼行數:20,代碼來源:productCategory.php

示例7: importProductCategories

 /**
  * Importing the category
  *
  * @param string $categoryId
  *
  * @return void|CatelogConnector
  */
 public function importProductCategories($categoryId = '')
 {
     $categories = $this->getCategoryLevel($categoryId);
     Log::logging(0, get_class($this), 'getting ProductCategories(mageId=' . $categoryId . ')', self::LOG_TYPE, '', __FUNCTION__);
     if (count($categories) === 0) {
         return;
     }
     try {
         $transStarted = false;
         try {
             Dao::beginTransaction();
         } catch (Exception $e) {
             $transStarted = true;
         }
         foreach ($categories as $category) {
             $mageId = trim($category->category_id);
             Log::logging(0, get_class($this), 'getting ProductCategory(mageId=' . $mageId . ')', self::LOG_TYPE, '', __FUNCTION__);
             $productCategory = ProductCategory::getByMageId($mageId);
             $category = $this->catalogCategoryInfo($mageId);
             if (!is_object($category)) {
                 continue;
             }
             $description = isset($category->description) ? trim($category->description) : trim($category->name);
             if (!$productCategory instanceof ProductCategory) {
                 Log::logging(0, get_class($this), 'found new category from magento(mageId=' . $mageId . ', name="' . $category->name . '"' . ')', self::LOG_TYPE, '', __FUNCTION__);
                 echo 'found new category from magento(mageId=' . $mageId . ', name="' . $category->name . '"' . ')' . "\n";
                 $productCategory = ProductCategory::create(trim($category->name), $description, ProductCategory::getByMageId(trim($category->parent_id)), true, $mageId);
             } else {
                 Log::logging(0, get_class($this), 'found existing category from magento(mageId=' . $mageId . ', name="' . $category->name . '", ID=' . $productCategory->getId() . ')', self::LOG_TYPE, '', __FUNCTION__);
                 echo 'found existing category from magento(mageId=' . $mageId . ', name="' . $category->name . '", ID=' . $productCategory->getId() . ')' . "\n";
                 $productCategory->setName(trim($category->name))->setDescription($description)->setParent(ProductCategory::getByMageId(trim($category->parent_id)));
             }
             $productCategory->setActive(trim($category->is_active) === '1')->setIncludeInMenu(isset($category->include_in_menu) && trim($category->include_in_menu) === '1')->setIsAnchor(trim($category->is_anchor) === '1')->setUrlKey(trim($category->url_key))->save();
             $this->importProductCategories(trim($category->category_id));
         }
         if ($transStarted === false) {
             Dao::commitTransaction();
         }
     } catch (Exception $ex) {
         if ($transStarted === false) {
             Dao::rollbackTransaction();
         }
         throw $ex;
     }
     return $this;
 }
開發者ID:larryu,項目名稱:magento-b2b,代碼行數:53,代碼來源:CatelogConnector.php


注:本文中的ProductCategory::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。