/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //dd($request);
     $product = new product();
     $product->name = $request->name;
     $product->price = $request->price;
     $product->save();
     return redirect()->route('product.index');
 }
Exemple #2
0
 public function createProduct()
 {
     $product = new product();
     $product->product_name = Input::get('product_name');
     $product->categories = Input::get('categories');
     $product->suppliers = Input::get('suppliers');
     $product->cost_price = Input::get('cost_price');
     $product->unit_price = Input::get('unit_price');
     $product->quantity = Input::get('quantity');
     $product->reorder_level = Input::get('reorder_level');
     $product->location = Input::get('location');
     $product->description = Input::get('description');
     $product->save();
     return View::make('product.index');
 }
    exit;
}
$expected = '{"customerId":2,"userId":{"id":4,"login":"******","active":0,"customerId":0,"firstName":"john","lastName":"Doe Jr","password":"","createdAt":"' . $client->createdAt . '","updatedAt":null,"expires":null,"loginCount":0},"productName":"product6","id":6}';
if ($obj->with('userId')->toJson() != $expected) {
    echo "Multisave problem\n";
    echo $obj->with('userId')->toJson();
    exit;
}
$u = new user();
$u->active = 'test';
$u->customerId = 'test';
$u->expires = 'test;';
$u->firstName = 'test';
$obj = new product();
$obj->userId = $u;
$obj->save();
if ($obj->save()) {
    echo "validation 1 failed\n";
    exit;
}
if (count($obj->errors) != 7) {
    print_r($obj->errors);
    echo "validation 2 failed\n";
    exit;
}
if (!user::byId(1) instanceof user) {
    echo "wrong return type1";
}
if (!is_array(user::ArrayBuilder()->byId(1))) {
    echo "wrong return type2";
}
Exemple #4
0
 function addAccessories($productId)
 {
     $product = new product($productId);
     $arr = $this->input->post('productCheck');
     if ($arr != "") {
         foreach ($arr as $row) {
             $accessory = new Product($row);
             $product->save(array('accessories' => $accessory));
             $accessory->clear();
         }
     }
 }
Exemple #5
0
$tf = new tf();
$tflist = $tf->get_assoc_array("tfID", "tfName");
$extra_options = array("-1" => "META: Project TF", "-2" => "META: Salesperson TF", config::get_config_item("mainTfID") => "Main Finance TF (" . tf::get_name(config::get_config_item("mainTfID")) . ")", config::get_config_item("outTfID") => "Outgoing Funds TF (" . tf::get_name(config::get_config_item("outTfID")) . ")", config::get_config_item("inTfID") => "Incoming Funds TF (" . tf::get_name(config::get_config_item("inTfID")) . ")");
// Prepend the META options to the tflist.
$tflist = $extra_options + $tflist;
$TPL["companyTF"] = $tflist[config::get_config_item("mainTfID")];
$TPL["taxTF"] = $tflist[config::get_config_item("taxTfID")];
$taxRate = config::get_config_item("taxPercent") / 100.0;
$TPL["taxRate"] = $taxRate;
if ($_POST["save"]) {
    $product->read_globals();
    $product->set_value("productActive", isset($_POST["productActive"]) ? 1 : 0);
    !$product->get_value("productName") and alloc_error("Please enter a Product Name.");
    !$product->get_value("sellPrice") and alloc_error("Please enter a Sell Price.");
    if (!$TPL["message"]) {
        $product->save();
        $productID = $product->get_id();
        // If they were in the middle of creating a sale, return them back there
        if ($_REQUEST["productSaleID"]) {
            alloc_redirect($TPL["url_alloc_productSale"] . "productSaleID=" . $_REQUEST["productSaleID"]);
        } else {
            alloc_redirect($TPL["url_alloc_product"] . "productID=" . $productID);
        }
    }
    $product->set_values();
} else {
    if ($_POST["delete"]) {
        $product->read_globals();
        $product->delete();
        alloc_redirect($TPL["url_alloc_productList"]);
    }
 function importProduct($file)
 {
     $handle = fopen($file->path, "r");
     $data = fgetcsv($handle, 10000, ",");
     //eDebug($data);
     foreach ($data as $key => $value) {
         $dataset[$value] = '';
     }
     //eDebug($dataset,true);
     $count = 1;
     $errorSet = array();
     $successSet = array();
     //$createCats = array();
     $product = null;
     /*
     0= id    
     1=parent_id    
     2=child_rank    
     3=title    
     4=model    
     5=warehouse_location    
     6=sef_url    
     7=meta_title    
     8=meta_keywords    
     9=meta_description    
     10=base_price    
     11=special_price    
     12=use_special_price    
     13=active_type    
     14=product_status_id    
     15=category1    
     16=category2    
     17=category3    
     18=category4    
     19=surcharge                                        
     20=rank   
     21=feed_title
     22=feed_body   
     */
     while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
         $count++;
         //eDebug($data, true);
         if (isset($data[0]) && $data[0] != 0) {
             $product = new product($data[0], false, false);
             if (empty($product->id)) {
                 $errorSet[$count] = $product->id . " is not a valid product ID.";
                 continue;
             }
         } else {
             //$errorSet[$count] = "Product ID not supplied.";
             //continue;
             $product = new product();
             //$product->save(false);
         }
         $checkTitle = trim($data[3]);
         if (empty($checkTitle)) {
             $errorSet[$count] = "No product name (title) supplied, skipping this record...";
             continue;
         }
         $product->parent_id = $data[1];
         $product->child_rank = $data[2];
         $product->title = stripslashes(stripslashes($data[3]));
         $product->body = utf8_encode(stripslashes(reportController::parseAndTrimImport($data[4], true)));
         //$product->body = utf8_encode(stripslashes(stripslashes(($data[4]))));
         $product->model = stripslashes(stripslashes($data[5]));
         $product->warehouse_location = stripslashes(stripslashes($data[6]));
         $product->sef_url = stripslashes(stripslashes($data[7]));
         $product->meta_title = stripslashes(stripslashes($data[8]));
         $product->meta_keywords = stripslashes(stripslashes($data[9]));
         $product->meta_description = stripslashes(stripslashes($data[10]));
         $product->tax_class_id = $data[11];
         $product->quantity = $data[12];
         $product->availability_type = $data[13];
         $product->base_price = $data[14];
         $product->special_price = $data[15];
         $product->use_special_price = $data[16];
         $product->active_type = $data[17];
         $product->product_status_id = $data[18];
         $product->surcharge = $data[31];
         $product->feed_title = stripslashes(stripslashes($data[33]));
         $product->feed_body = stripslashes(stripslashes($data[34]));
         if (empty($product->id)) {
             $product->minimum_order_quantity = 1;
         }
         if ($product->parent_id == 0) {
             $createCats = array();
             $createCatsRank = array();
             for ($x = 19; $x <= 30; $x++) {
                 if (!empty($data[$x])) {
                     $result = $this->parseCategory($data[$x]);
                 } else {
                     continue;
                 }
                 if (is_numeric($result)) {
                     $createCats[] = $result;
                     $createCatsRank[$result] = $data[32];
                 } else {
                     $errorSet[$count][] = $result;
                     continue 2;
                 }
             }
         }
         /*[0] => id
           [1] => parent_id
           [2] => child_rank
           [3] => title
           [4] => model
           [5] => warehouse_location
           [6] => sef_url
           [7] => meta_title
           [8] => meta_keywords
           [9] => meta_description
           [10] => base_price
           [11] => special_price
           [12] => use_special_price
           [13] => active_type
           [14] => product_status_id
           [15] => category1
           [16] => category2
           [17] => category3
           [18] => category4
           [19] => surcharge*/
         //eDebug($createCats,true);
         if (!empty($product->user_input_fields) && is_array($product->user_input_fields)) {
             $product->user_input_fields = serialize($product->user_input_fields);
         }
         //eDebug($product->user_input_fields);
         if (!empty($product->user_input_fields) && !is_array($product->user_input_fields)) {
             $product->user_input_fields = str_replace("'", "\\'", $product->user_input_fields);
         }
         //eDebug($product->user_input_fields,true);
         $product->save(false);
         //eDebug($product->body);
         //sort order and categories
         if ($product->parent_id == 0) {
             $product->saveCategories($createCats, $createCatsRank);
             //eDebug($createCatsRank);
         }
         echo "Sucessfully imported row " . $count . ", product: " . $product->title . "<br/>";
         //eDebug($product);
     }
     if (count($errorSet)) {
         echo "<br/><hr><br/><font color='red'>The following records were NOT imported:<br/>";
         foreach ($errorSet as $row => $err) {
             echo "Row: " . $row . ". Reason:<br/>";
             if (is_array($err)) {
                 foreach ($err as $e) {
                     echo "--" . $e . "<br/>";
                 }
             } else {
                 echo "--" . $err . "<br/>";
             }
         }
         echo "</font>";
     }
 }