當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。