Ejemplo n.º 1
0
 function add($variation_id)
 {
     $v = \App\ProductVariation::find($variation_id);
     if (!$v) {
         session()->flash('danger', 'Sorry, that product does not exist.');
         return redirect()->route('cart.view');
     }
     $item = ['sku' => $v->id, 'description' => $v->product->name, 'price' => $v->price, 'quantity' => 1];
     $result = $this->cart->insert($item);
     session()->flash('success', 'Product added.');
     return redirect()->route('cart.view');
 }
 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();
 }