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


PHP Product::create方法代码示例

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


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

示例1: test_create

 public function test_create()
 {
     /** === Test Data === */
     $SKU = 'sku';
     $NAME = 'product name';
     $IS_ACTIVE = true;
     $PRICE = 43.21;
     $WEIGHT = 54.321;
     $ATTR_SET_ID = 8;
     $PRODUCT_ID = 543;
     /** === Setup Mocks === */
     // $crit = $this->_manObj->create(\Magento\Framework\Api\SearchCriteriaInterface::class);
     $mCrit = $this->_mock(\Magento\Framework\Api\SearchCriteriaInterface::class);
     $this->mManObj->shouldReceive('create')->once()->andReturn($mCrit);
     // $list = $this->_mageRepoAttrSet->getList($crit);
     $mList = $this->_mock(\Magento\Eav\Api\Data\AttributeSetSearchResultsInterface::class);
     $this->mMageRepoAttrSet->shouldReceive('getList')->once()->andReturn($mList);
     // $items = $list->getItems();
     // $attrSet = reset($items);
     $mAttrSet = $this->_mock(\Magento\Eav\Model\Entity\Attribute\Set::class);
     $mList->shouldReceive('getItems')->once()->andReturn([$mAttrSet]);
     // $attrSetId = $attrSet->getId();
     $mAttrSet->shouldReceive('getId')->once()->andReturn($ATTR_SET_ID);
     // $product = $this->_manObj->create(ProductInterface::class);
     $mProduct = $this->_mock(\Magento\Catalog\Api\Data\ProductInterface::class);
     $this->mManObj->shouldReceive('create')->once()->andReturn($mProduct);
     $mProduct->shouldReceive('setSku', 'setName', 'setStatus', 'setPrice', 'setWeight', 'setAttributeSetId', 'setTypeId', 'setUrlKey');
     // $saved = $this->_mageRepoProd->save($product);
     $this->mMageRepoProd->shouldReceive('save')->once()->andReturn($mProduct);
     // $result = $saved->getId();
     $mProduct->shouldReceive('getId')->once()->andReturn($PRODUCT_ID);
     /** === Call and asserts  === */
     $res = $this->obj->create($SKU, $NAME, $IS_ACTIVE, $PRICE, $WEIGHT);
     $this->assertEquals($PRODUCT_ID, $res);
 }
开发者ID:praxigento,项目名称:mobi_mod_mage2_odoo,代码行数:35,代码来源:Product_Test.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $validation = Validator::make($input, Product::$rules);
     if ($validation->passes()) {
         $this->product->create($input);
         Image::upload(Input::file('image'), 'products/' . $this->product->id, 'main.jpg', true);
         return Redirect::route('products.index');
     }
     return Redirect::route('products.create')->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
 }
开发者ID:maldewar,项目名称:jidou,代码行数:16,代码来源:ProductsController.php

示例3: run

 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 100) as $index) {
         Product::create(['name' => $faker->userName, 'description' => $faker->text(100 + $faker->numberBetween(10, 150)), 'price' => $faker->randomFloat(2, 5, 30), 'icon' => 'http://www.bumultimedia.com/trabajos/marcaDiferenciada/mansionMascotas/images/gallery_' . $faker->numberBetween(1, 5) . '.jpg', 'category' => $faker->numberBetween(1, 5)]);
     }
 }
开发者ID:jairom0704,项目名称:dental_office,代码行数:7,代码来源:ProductTableSeeder.php

示例4: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     DB::table('products')->delete();
     Product::create(array('name' => 'krasse Jacke!', 'article_number' => '823928139123', 'description' => 'super tolle Jacke, die es ordentlich in sich hat. Kaum wo anders zu finden. Selbst wenn man ewig sucht, wird man nicht so eine tolle Jacke finden!'));
     Product::create(array('name' => 'coole Brille!', 'article_number' => '82399991232', 'description' => 'Eine sehr modische Brille'));
 }
开发者ID:mhger,项目名称:fablife,代码行数:12,代码来源:ProductTableSeeder.php

示例5: run

 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 100) as $index) {
         Product::create([]);
     }
 }
开发者ID:RedTechs,项目名称:century-music,代码行数:7,代码来源:ProductsTableSeeder.php

示例6: run

 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Product::create(['name' => $faker->word, 'product_brand_type_id' => $faker->numberBetween($min = 1, $max = 3), 'original_price' => $faker->numberBetween($min = 100, $max = 1000), 'product_status_id' => $faker->numberBetween($min = 1, 3)]);
     }
 }
开发者ID:bryanestrito,项目名称:datawarehouse_etl,代码行数:7,代码来源:ProductsTableSeeder.php

示例7: run

 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Product::create(['product_name' => $faker->word, 'details' => $faker->paragraph, 'picture' => 'uploads/products/1default.jpg', 'min_price' => $faker->randomDigit, 'max_price' => $faker->randomDigitNotNull, 'crop_id' => 1, 'location' => $faker->country, 'expiry_date' => $faker->date('Y--m-d')]);
     }
 }
开发者ID:talha08,项目名称:Farmer-Bazar,代码行数:7,代码来源:ProductsTableSeeder.php

示例8: 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

示例9: run

 public function run()
 {
     //$faker = Faker::create();这个可能是随机数据模块
     DB::table('products')->delete();
     foreach (range(1, 2) as $index) {
         Product::create(['name' => '狗屎' . $index, 'category' => 'PRODUCT_CATEGORY_xxsp']);
     }
 }
开发者ID:Kangaroos,项目名称:oneshike,代码行数:8,代码来源:ProductsTableSeeder.php

示例10: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $products = array(['name' => 'Apple', 'description' => 'test', 'category' => 'Mobile', 'price' => '200'], ['name' => 'Samsung', 'description' => 'test', 'category' => 'TV', 'price' => '300'], ['name' => 'Mi', 'description' => 'test', 'category' => 'Laptop', 'price' => '500'], ['name' => 'Nokia', 'description' => 'test', 'category' => 'Fan', 'price' => '600']);
     // Loop through each user above and create the record for them in the database
     foreach ($products as $product) {
         Product::create($products);
     }
 }
开发者ID:ankitdacoder,项目名称:sports,代码行数:13,代码来源:DatabaseSeeder.php

示例11: run

 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 20) as $index) {
         $name = $faker->sentence;
         Product::create(['name' => $name, 'short_name' => Str::slug($name), 'sku' => $faker->uuid, 'sell_price' => $faker->randomFloat(2, 5, 125), 'short_description' => $faker->paragraph, 'description' => $faker->text, 'meta_title' => $faker->paragraph, 'meta_description' => $faker->text, 'product_type_id' => $faker->numberBetween(0, 10)]);
     }
 }
开发者ID:nguyendaivu,项目名称:imagestock,代码行数:8,代码来源:ProductTableSeeder.php

示例12: run

 public function run()
 {
     $faker = Faker::create();
     $i = 0;
     foreach (range(1, 10) as $index) {
         $i++;
         Product::create(['name' => 'product' . $i, 'description' => 'this is just a description' . $i, 'price' => '1234.56', 'category_id' => rand(1, 4), 'image' => '/img/products/1421873359-mac-book.jpg']);
     }
 }
开发者ID:Pixelsltd,项目名称:e-commerce-1,代码行数:9,代码来源:ProductsTableSeeder.php

示例13: updateProduct

function updateProduct($pro, $fileName, $line)
{
    $clientScript = CatelogConnector::getConnector(B2BConnector::CONNECTOR_TYPE_CATELOG, getWSDL(), 'B2BUser', 'B2BUser');
    try {
        $transStarted = false;
        try {
            Dao::beginTransaction();
        } catch (Exception $e) {
            $transStarted = true;
        }
        $sku = trim($pro['sku']);
        $product = Product::getBySku($pro['sku']);
        $mageId = trim($pro['product_id']);
        $name = trim($pro['name']);
        $short_description = trim($pro['short_description']);
        $description = trim($pro['description']);
        $weight = trim($pro['weight']);
        $statusId = trim($pro['status']);
        $price = trim($pro['price']);
        $specialPrice = trim($pro['special_price']);
        $specialPrice_From = trim($pro['special_from_date']) === '' ? trim($pro['special_from_date']) : null;
        $specialPrice_To = trim($pro['special_to_date']) === '' ? trim($pro['special_to_date']) : null;
        $supplierName = trim($pro['supplier']);
        $attributeSet = ProductAttributeSet::get(trim($pro['attributeSetId']));
        if (!$product instanceof Product) {
            $product = Product::create($sku, $name);
        }
        $asset = ($assetId = trim($product->getFullDescAssetId())) === '' || !($asset = Asset::getAsset($assetId)) instanceof Asset ? Asset::registerAsset('full_desc_' . $sku, $description, Asset::TYPE_PRODUCT_DEC) : $asset;
        $product->setName($name)->setMageId($mageId)->setAttributeSet($attributeSet)->setShortDescription($short_description)->setFullDescAssetId(trim($asset->getAssetId()))->setIsFromB2B(true)->setStatus(ProductStatus::get($statusId))->setSellOnWeb(true)->setManufacturer($clientScript->getManufacturerName(trim($pro['manufacturer'])))->save()->clearAllPrice()->addPrice(ProductPriceType::get(ProductPriceType::ID_RRP), $price)->addInfo(ProductInfoType::ID_WEIGHT, $weight);
        if ($specialPrice !== '') {
            $product->addPrice(ProductPriceType::get(ProductPriceType::ID_CASUAL_SPECIAL), $specialPrice, $specialPrice_From, $specialPrice_To);
        }
        if ($supplierName !== '') {
            $product->addSupplier(Supplier::create($supplierName, $supplierName, true));
        }
        if (isset($pro['categories']) && count($pro['categories']) > 0) {
            $product->clearAllCategory();
            foreach ($pro['categories'] as $cateMageId) {
                if (!($category = ProductCategory::getByMageId($cateMageId)) instanceof ProductCategory) {
                    continue;
                }
                $product->addCategory($category);
            }
        }
        if ($transStarted === false) {
            Dao::commitTransaction();
        }
        //TODO remove the file
        removeLineFromFile($fileName, $line);
        echo $product->getId() . " => done! \n";
    } catch (Exception $ex) {
        if ($transStarted === false) {
            Dao::rollbackTransaction();
        }
        throw $ex;
    }
}
开发者ID:larryu,项目名称:magento-b2b,代码行数:57,代码来源:test.php

示例14: Product

 /**
  * Find any items in the product catalogue with a matching SKU, good for
  * adding "Order again" links in account panels or finding "Most ordered"
  * etc.
  *
  * @return Product
  */
 public function Product()
 {
     // If the SKU is set, and it matches a product, return product
     if ($this->SKU && ($product = Product::get()->filter("SKU", $this->SKU)->first())) {
         return $product;
     }
     // If nothing has matched, return an empty product
     return Product::create();
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:16,代码来源:OrderItem.php

示例15: store

 /**
  * Store a newly created product in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Product::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     Product::create($data);
     return Redirect::route('products.index');
 }
开发者ID:NocturnalWare,项目名称:managedotband,代码行数:14,代码来源:ProductsController.php


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