本文整理汇总了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]);
}
示例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;
}
示例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());
}
示例4: injectProductCategory
public function injectProductCategory()
{
$validator = Validator::make($data = Input::all(), ProductCategory::$rules);
if ($validator->fails()) {
return 'failt';
}
ProductCategory::create($data);
return 'worked';
}
示例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');
}
}
}
示例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();
}
示例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;
}