Exemplo n.º 1
0
 public function index()
 {
     $flavors = [];
     foreach (Flavor::all() as $flavor) {
         $flavors[] = $flavor->serialize();
     }
     return response()->json(['flavors' => $flavors]);
 }
Exemplo n.º 2
0
 public function create(Request $request)
 {
     $server = new Server();
     $server->hostname = $request->input('server.hostname');
     $server->ip = $request->input('server.ip');
     $server->status = 'on';
     $server->affectRandomIpAddress();
     $flavor = Flavor::find($request->input('server.flavor'));
     if (isset($flavor)) {
         $server->flavor()->associate($flavor);
     }
     $image = Image::find($request->input('server.image'));
     if (isset($image)) {
         $server->image()->associate($image);
     }
     $server->save();
     sleep(10);
     return response()->json(['servers' => [$server->serialize()], 'images' => [$server->image->serialize()], 'flavors' => [$server->flavor->serialize()]]);
 }
 function import_product_variation()
 {
     $o = $this->o;
     $p = Product::where('sku', $o->sku)->first();
     if (!$p) {
         $this->errors[] = sprintf("Product %s not found for Product Variation row %s. Skipping this variation.", $o->sku, $this->idx);
         return;
     }
     $pv = ProductVariation::where('product_id', $p->id)->where('subsku', $o->subsku)->first();
     if (!$pv) {
         $pv = new ProductVariation();
     }
     $pv->product_id = $p->id;
     foreach (['name', 'subsku', 'size', 'rrp', 'price', 'servings', 'stock', 'weight', 'width', 'length', 'depth'] as $field_name) {
         $pv->{$field_name} = $o->{$field_name};
     }
     if ($o->flavor) {
         $f = Flavor::where('name', $o->flavor)->first();
         if (!$f) {
             $this->warnings[] = sprintf("Flavor %s for product %s (row %d) was not found in Flavors. Skipping flavor association.", $o->flavor, $o->sku, $this->idx);
         } else {
             $pv->flavor_id = $f->id;
         }
     }
     $pv->cs = strtoupper($o->cs) == 'Y';
     // Anything except Y means no
     $pv->is_active = !(strtoupper($o->is_active) == 'N');
     // Anything except N means yes
     $pv->image = $this->process_image($o->image_url, 'product_variations');
     $pv->save();
 }