/**
  *   Handle post data and show our create form
  */
 public function postCreate()
 {
     $error = false;
     Gallery::create(['image' => Input::file('images')]);
     if ($product = Products::create(Input::except('images', '_token'))) {
         return Redirect::to(admin_path('products/edit/' . $product->id));
     }
     View::share('error', 'Couldn’t create your product.');
     return self::getCreate();
 }
 public function run()
 {
     $faker = Faker\Factory::create();
     //Products::truncate();
     $suppliers = Suppliers::all()->lists('id');
     $categories = Categories::all()->lists('id');
     for ($i = 0; $i < 20; $i++) {
         $products = Products::create(array('name' => $faker->word, 'quantity' => $faker->numberBetween(1, 900), 'unitPrice' => $faker->randomFloat(5, 1, 5000), 'details' => $faker->text, 'color' => $faker->colorName, 'supplierProductId' => $faker->randomNumber, 'supplierId' => $faker->randomElement($suppliers), 'categoryId' => $faker->randomElement($categories)));
     }
 }
Beispiel #3
0
 public static function create($data)
 {
     $response = new Response();
     try {
         $data = json_decode($data, true);
         $category = Categories::findFirst($data->categoryId);
         if ($category !== FALSE) {
             /** @var Products $products */
             $product = new Products();
             $product->setAttributes($data);
             $response->data = $product->create();
             $response->status = $response::STATUS_CREATED;
         } else {
             $response->status = $response::STATUS_BAD_REQUEST;
             $response->addError('CATEGORIES_NOT_FOUND');
         }
     } catch (Exception $e) {
         $response->setException($e);
     } finally {
         return $response->toArray();
     }
 }
Beispiel #4
0
$products = new Products();
$products->url();
$settings['collection'] = $db->select("collections", "id={$products->collection_id}", 'name,barcodes,variation_ids', 1);
$settings['site'] = $db->select("settings", "id='1'", 'barcodes', 1);
$collection_name = $settings['collection']['name'];
if (isset($_POST['submit'])) {
    if (isset($_GET['move'])) {
        $db->update("products", "collection_id", $_POST['collection_id'], $_GET['move']);
        $html->redirection("products.php?c=" . $_POST['collection_id'] . "&p=" . $_GET['move']);
    } else {
        $products->set_data();
        $error = $products->check_data();
        if (!$error) {
            switch ($_GET['p']) {
                case 'add':
                    $products->create();
                    $html->redirection("products.php?c=" . $_GET['c'] . "&p=add");
                    break;
                default:
                    $products->update();
                    $html->redirection("products.php?c=" . $_GET['c'] . (isset($_GET['f']) ? "&f=" . $_GET['f'] : ''));
                    break;
            }
        }
    }
}
if (isset($_GET['p'])) {
    $products->get_data();
    echo "<div id='page-title' class='row'>";
    echo "<div class='col-xs-12 col-sm-6'>";
    $html->title($_GET['p'] == "add" ? "Add Product" : "{$products->name}", "Collection: {$collection_name}", "left");
Beispiel #5
0
<?php

$product = new Products();
$product->product_types_id = 1;
$product->name = 'Artichoke';
$product->price = 10.5;
$product->active = 'Y';
$product->create();