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);
 }
Example #2
0
 /**
  * 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.');
 }
 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)]);
     }
 }
Example #4
0
 /**
  * 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'));
 }
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 100) as $index) {
         Product::create([]);
     }
 }
 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)]);
     }
 }
 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')]);
     }
 }
Example #8
0
 /**
  * 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]);
 }
 public function run()
 {
     //$faker = Faker::create();这个可能是随机数据模块
     DB::table('products')->delete();
     foreach (range(1, 2) as $index) {
         Product::create(['name' => '狗屎' . $index, 'category' => 'PRODUCT_CATEGORY_xxsp']);
     }
 }
Example #10
0
 /**
  * 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);
     }
 }
 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)]);
     }
 }
 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']);
     }
 }
Example #13
0
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;
    }
}
 /**
  * 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();
 }
 /**
  * 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');
 }
Example #16
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     $data = array('product_name' => Input::get('pro_name'), 'bike_cc' => Input::get('pro_cc'), 'model' => Input::get('pro_model'));
     $insert = Product::create($data);
     if ($insert) {
         return json_encode(array('error' => 0, 'success' => 1));
     } else {
         return json_encode(array('error' => 1, 'success' => 0));
     }
 }
 /**
  * Store a newly created product in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), Product::$rules);
     if ($validator->passes()) {
         Product::create(array('unit_id' => Input::get('unit_id'), 'name' => Input::get('name'), 'price' => Input::get('price'), 'cost' => Input::get('cost'), 'description' => Input::get('description'), 'created_at' => Carbon\Carbon::today(), 'producer' => Input::get('producer'), 'country' => Input::get('country')));
         return Response::json(array('success' => true, 'message' => array('type' => 'success', 'msg' => 'Thêm hàng hóa thành công!')));
     } else {
         return Response::json(array('success' => false, 'errors' => $validator->errors()));
     }
 }
Example #18
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $products = array(array('name' => 'Nova 1'), array('name' => 'Nova 2'), array('name' => 'Nova 3'));
     // In production, don't use Nova 3 for now
     if (App::environment() == 'production') {
         $products[2]['display'] = (int) false;
     }
     foreach ($products as $product) {
         Product::create($product);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::get();
     $v = $this->validate($input);
     if ($v->passes()) {
         unset($input['_token']);
         Product::create(Input::get());
         return Redirect::to('products')->with('message', trans('data.success_saved'));
     } else {
         return Redirect::back()->withInput()->withErrors($v)->with('message', trans('data.error_saving'));
     }
 }
 /**
  * Find the current category via its URL
  *
  * @return Product
  *
  */
 public static function get_current_product()
 {
     $segment = Controller::curr()->request->param('URLSegment');
     $return = null;
     if ($segment) {
         $return = Product::get()->filter(array('URLSegment' => $segment, "Disabled" => 0))->first();
     }
     if (!$return) {
         $return = Product::create();
     }
     return $return;
 }
 public function run()
 {
     Product::create(['title' => 'Product 1', 'alias' => 'product-1', 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'Какойто русский тект. Кирилица т.е.', 'price' => '12343', 'category_id' => '1']);
     Product::create(['title' => 'Product 2', 'alias' => 'product-2', 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'Какойто русский тект. Кирилица т.е.', 'price' => '123424', 'category_id' => '1']);
     Product::create(['title' => 'Product 3', 'alias' => 'product-3', 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'Какойто русский тект. Кирилица т.е.', 'price' => '41234', 'category_id' => '1']);
     Product::create(['title' => 'Product 4', 'alias' => 'product-4', 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'Какойто русский тект. Кирилица т.е.', 'price' => '5467', 'category_id' => '2']);
     Product::create(['title' => 'Product 5', 'alias' => 'product-5', 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'Какойто русский тект. Кирилица т.е.', 'price' => '7567', 'category_id' => '3']);
     Product::create(['title' => 'Product 6', 'alias' => 'product-6', 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'Какойто русский тект. Кирилица т.е.', 'price' => '245', 'category_id' => '2']);
     Product::create(['title' => 'Product 7', 'alias' => 'product-7', 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'Какойто русский тект. Кирилица т.е.', 'price' => '2345', 'category_id' => '1']);
     Product::create(['title' => 'Product 8', 'alias' => 'product-8', 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'Какойто русский тект. Кирилица т.е.', 'price' => '53245', 'category_id' => '2']);
     Product::create(['title' => 'Product 9', 'alias' => 'product-9', 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'Какойто русский тект. Кирилица т.е.', 'price' => '5245', 'category_id' => '1']);
 }
 public function run()
 {
     $faker = Faker::create();
     $word = array('trials', 'rebills', 'dp', 'returned');
     foreach (range(1, 5) as $index) {
         $digit = $faker->numberBetween($min = 0, $max = 3);
         $amount = Record::where(function ($query) use($index) {
             $query->where('product_id', $index);
         })->sum('amount');
         $product = Product::create(['name' => $faker->word, 'product_id' => $index, "site_link" => $faker->word, 'description' => $faker->paragraph(1), "price_per_bottle" => $faker->word, "manufacturer" => $faker->firstNameMale, "inhouse" => $amount]);
     }
 }
 public function run()
 {
     //se ingresa el libro de darwin
     //DB::statement("INSERT INTO lor_lecture (title, author, year, publisher, content, created_at, updated_at, deleted_at) VALUES ('El origen de las especies', 'Charles Darwin', '1859', 'Dominio publico', 'temas vivos.', NOW(),NOW(), NULL);");
     $user = User::create(array('profile' => 'super_admin', 'firstname' => 'Alexander Andres Londono Espejo', 'username' => 'admin', 'email' => '*****@*****.**', 'password' => Hash::make('admin')));
     $user->roles()->attach(1);
     $user->roles()->attach(2);
     $user->roles()->attach(3);
     $user->roles()->attach(4);
     $user->roles()->attach(5);
     $user->roles()->attach(6);
     $user->roles()->attach(7);
     $user->roles()->attach(8);
     $user->roles()->attach(9);
     $user->roles()->attach(10);
     $user->roles()->attach(11);
     $user->roles()->attach(12);
     $user->roles()->attach(13);
     $user->roles()->attach(14);
     $user->roles()->attach(15);
     $user->roles()->attach(16);
     $user->roles()->attach(17);
     $user->roles()->attach(18);
     $user->roles()->attach(19);
     $user->roles()->attach(20);
     $user->roles()->attach(21);
     $user->roles()->attach(22);
     $user->roles()->attach(23);
     $user->roles()->attach(24);
     $user->roles()->attach(25);
     $user->roles()->attach(26);
     $user->roles()->attach(27);
     $user->roles()->attach(28);
     $user->roles()->attach(29);
     $user->roles()->attach(30);
     $user->roles()->attach(31);
     $user->roles()->attach(32);
     $faker = Faker\Factory::create();
     $count_client = 50;
     foreach (range(1, $count_client) as $index) {
         $user = User::create(['firstname' => $faker->firstName, 'lastname' => $faker->lastName, 'username' => 'admin' . $index, 'email' => $faker->email, 'identification' => $faker->numberBetween(19999999, 99999999), 'password' => Hash::make('admin' . $index)]);
         //Ingreso datos de prueba de clientes
         $client = Client::create(['name' => $faker->company, 'address' => 'Caucasia Antioquia', 'enable' => 'SI']);
         //Ingreso datos de prueba de proveedores
         $provider = Provider::create(['name' => $faker->company, 'email' => $faker->email, 'telephone' => $faker->numberBetween(19999999, 99999999), 'country' => 'Colombia', 'department' => 'Antioquia', 'city' => 'Medellin', 'enable' => 'SI']);
         //Ingreso datos de prueba de costos
         $costs = Cost::create(['name' => $faker->company, 'type' => 'Otro', 'value' => $faker->numberBetween(1999, 99999), 'description' => $faker->company, 'resposible' => 'Alexander', 'enable' => 'SI']);
         //Ingreso datos de prueba de categoria
         $category = Category::create(['name' => $faker->company, 'description' => '', 'enable' => 'SI']);
         //Ingreso datos de prueba de productos
         $product = Product::create(['name' => $faker->company, 'description' => '', 'cost' => $faker->numberBetween(1999, 9999), 'value' => $faker->numberBetween(19999, 99999), 'enable' => 'SI']);
     }
 }
 public function run()
 {
     Product::create(['user_id' => '1', 'category_id' => '3', 'type_id' => '1', 'price_id' => '3', 'price' => '30000000', 'name' => 'Xe máy Yamaha Exciter', 'description' => 'Xe máy Yamaha Exciter', 'avatar' => '01.jpg', 'city_id' => '1', 'lat' => '21.00296184', 'long' => '105.85202157', 'position' => '1', 'status' => '1']);
     Product::create(['user_id' => '1', 'category_id' => '5', 'type_id' => '1', 'price_id' => '2', 'price' => '4500000', 'name' => 'Máy ảnh Canon 600D', 'description' => 'Máy ảnh Canon 600D', 'avatar' => '11.jpg', 'city_id' => '1', 'lat' => '21.00296184', 'long' => '105.85202157', 'position' => '1', 'status' => '1']);
     Product::create(['user_id' => '1', 'category_id' => '5', 'type_id' => '1', 'price_id' => '2', 'price' => '7500000', 'name' => 'Máy ảnh Canon EOS 5D', 'description' => 'Máy ảnh Canon EOS 5D', 'avatar' => '21.jpg', 'city_id' => '1', 'lat' => '21.00296184', 'long' => '105.85202157', 'position' => '1', 'status' => '2']);
     Product::create(['user_id' => '1', 'category_id' => '3', 'type_id' => '1', 'price_id' => '4', 'price' => '800000000', 'name' => 'Ô tô Chevrolet', 'description' => 'Ô tô Chevrolet', 'avatar' => '31.jpg', 'city_id' => '1', 'lat' => '21.00296184', 'long' => '105.85202157', 'position' => '1', 'status' => '1']);
     Product::create(['user_id' => '1', 'category_id' => '7', 'type_id' => '1', 'price_id' => '2', 'price' => '1200000', 'name' => 'Ghế FINE NDTO-CH152ASLP', 'description' => 'Ghế FINE NDTO-CH152ASLP', 'avatar' => '41.jpg', 'city_id' => '1', 'lat' => '21.00296184', 'long' => '105.85202157', 'position' => '1', 'status' => '1']);
     Product::create(['user_id' => '1', 'category_id' => '8', 'type_id' => '1', 'price_id' => '1', 'price' => '350000', 'name' => 'Bếp Gas CanZy CZ-370', 'description' => 'Bếp Gas CanZy CZ-370', 'avatar' => '51.jpg', 'city_id' => '1', 'lat' => '21.00296184', 'long' => '105.85202157', 'position' => '1', 'status' => '1']);
     Product::create(['user_id' => '1', 'category_id' => '6', 'type_id' => '1', 'price_id' => '1', 'price' => '550000', 'name' => 'Set váy áo cute nữ', 'description' => 'Set váy áo cute nữ', 'avatar' => '61.jpg', 'city_id' => '1', 'lat' => '21.00296184', 'long' => '105.85202157', 'position' => '1', 'status' => '1']);
     Product::create(['user_id' => '2', 'category_id' => '1', 'type_id' => '1', 'price_id' => '2', 'price' => '1500000', 'name' => 'Mật ong rừng', 'description' => 'Mật ong rừng', 'avatar' => '71.jpg', 'city_id' => '1', 'lat' => '21.00296184', 'long' => '105.85202157', 'position' => '1', 'status' => '1']);
     Product::create(['user_id' => '2', 'category_id' => '2', 'type_id' => '1', 'price_id' => '1', 'price' => '300000', 'name' => 'Guitar A380 Mặt gỗ', 'description' => 'Guitar A380 Mặt gỗ', 'avatar' => '81.jpg', 'city_id' => '1', 'lat' => '21.00296184', 'long' => '105.85202157', 'position' => '1', 'status' => '1']);
     Product::create(['user_id' => '3', 'category_id' => '4', 'type_id' => '1', 'price_id' => '4', 'price' => '1300000000', 'name' => 'Căn hộ 1 phòng ngủ HH1B-Linh Đàm', 'description' => 'Căn hộ 1 phòng ngủ HH1B-Linh Đàm', 'avatar' => '91.jpg', 'city_id' => '1', 'lat' => '21.00296184', 'long' => '105.85202157', 'position' => '1', 'status' => '1']);
 }
 public function run()
 {
     $faker = $this->getFaker();
     $categories = Category::all();
     foreach ($categories as $category) {
         for ($i = 0; $i < rand(-1, 10); $i++) {
             $name = ucwords($faker->word);
             $stock = $faker->randomNumber(0, 100);
             $price = $faker->randomFloat(2, 5, 100);
             Product::create(["name" => $name, "stock" => $stock, "price" => $price, "category_id" => $category->id]);
         }
     }
 }
 public function run()
 {
     DB::table('tires')->delete();
     DB::table('rims')->delete();
     DB::table('products')->delete();
     Product::create(array('id' => 1, 'price' => 100.0, 'original_price' => 50.0, 'quantity' => 4));
     Rim::create(array('material' => 'steel', 'size' => '15', 'bolt_pattern' => '3', 'product_id' => 1));
     Product::create(array('id' => 2, 'price' => 200.0, 'original_price' => 100.0, 'quantity' => 4));
     Tire::create(array('brand_name' => 'Goodrich', 'description' => 'Very good tire', 'size' => '15', 'model' => '2006', 'product_id' => 2, 'rim_id' => 1));
     Product::create(array('id' => 3, 'price' => 150.0, 'original_price' => 100.0, 'quantity' => 7));
     Tire::create(array('brand_name' => 'Dynapro', 'description' => 'Very good tire. 98% Thread', 'size' => '16', 'model' => '2009', 'product_id' => 3, 'rim_id' => null));
     Product::create(array('id' => 4, 'price' => 200.0, 'original_price' => 150.0, 'quantity' => 3));
     Rim::create(array('material' => 'alloy', 'size' => '19', 'bolt_pattern' => '6', 'product_id' => 4));
 }
 public function run()
 {
     $faker = $this->getFaker();
     $categories = Category::all();
     foreach ($categories as $category) {
         for ($i = 0; $i < rand(-1, 10); $i++) {
             $name = ucwords($faker->word);
             $stock = 1;
             $desc = $faker->text();
             $price = $faker->randomFloat(2, 5, 100);
             Product::create(["category_id" => $category->id, "title" => $name, "description" => $desc, "price" => $price, "availability" => $stock]);
         }
     }
 }
Example #28
0
 public function create()
 {
     if (!isset($_POST['name']) || !isset($_POST['price']) || !isset($_POST['description']) || !isset($_POST['pwd']) || !isset($_POST['img_src']) || !isset($_POST['date'])) {
         return call('pages', 'error');
     }
     require_once 'models/user.php';
     if (!User::find($_SESSION['username'], $_POST['pwd'])) {
         $_SESSION['alert'] = "Wrong password!";
         return header("Location: index.php?controller=products&action=index");
     }
     $price = floatval($_POST['price']);
     Product::create($_POST['name'], $_POST['img_src'], $price, $_POST['description'], $_POST['date']);
     $_SESSION['notice'] = "Added product successfully!";
     header("Location: index.php?controller=products&action=index");
 }
Example #29
0
 public function testOrderCreateUpdateRetrievePay()
 {
     Stripe::setApiKey('sk_test_JieJALRz7rPz7boV17oMma7a');
     $ProductID = 'silver-' . self::generateRandomString(20);
     $p = Product::create(array('name' => 'Silver Product', 'id' => $ProductID, 'url' => 'www.stripe.com/silver', 'shippable' => false));
     $SkuID = 'silver-sku-' . self::generateRandomString(20);
     $sku = SKU::create(array('price' => 500, 'currency' => 'usd', 'id' => $SkuID, 'inventory' => array('type' => 'finite', 'quantity' => 40), 'product' => $ProductID));
     $order = Order::create(array('items' => array(0 => array('type' => 'sku', 'parent' => $SkuID)), 'currency' => 'usd', 'email' => '*****@*****.**'));
     $order->metadata->foo = "bar";
     $order->save();
     $stripeOrder = Order::retrieve($order->id);
     $this->assertSame($order->metadata->foo, "bar");
     $order->pay(array('source' => array('object' => 'card', 'number' => '4242424242424242', 'exp_month' => '05', 'exp_year' => '2017')));
     $this->assertSame($order->status, 'paid');
 }
Example #30
0
 /**
  * Create product object
  * 
  * @param   array   $request_data   Request data
  * @return  int     ID of product
  *
  * @url     POST product/
  */
 function post($request_data = NULL)
 {
     if (!DolibarrApiAccess::$user->rights->produit->creer) {
         throw new RestException(401);
     }
     // Check mandatory fields
     $result = $this->_validate($request_data);
     foreach ($request_data as $field => $value) {
         $this->product->{$field} = $value;
     }
     $result = $this->product->create(DolibarrApiAccess::$user);
     if ($result < 0) {
         throw new RestException(503, 'Error when creating product : ' . $this->product->error);
     }
     return $this->product->id;
 }