Beispiel #1
0
 static function goal()
 {
     return Tier::where('type', 'Goal');
 }
 function import_product()
 {
     $o = $this->o;
     $p = Product::where('sku', $o->sku)->first();
     if (!$p) {
         $p = new Product();
     }
     $p->sku = $o->sku;
     $p->name = $o->name;
     $p->is_featured = strtoupper($o->is_featured) == 'Y';
     // Anything except Y means no
     $p->is_active = !(strtoupper($o->is_active) == 'N');
     // Anything except N means yes
     $b = Tier::brand()->where('ref', $o->brand)->first();
     if ($b) {
         $p->brand_id = $b->id;
     } else {
         $this->errors[] = sprintf("Brand %s in product %s (row %d) is missing from Product Tiers. Skipping this product.", $o->brand, $o->sku, $this->idx);
         return;
     }
     $p->banner = $this->process_image($o->banner_url, 'product_banners');
     $p->save();
     ProductTier::where('product_id', $p->id)->delete();
     $this->import_product_tier($p, $o->categories, 'category', $o->sku);
     $this->import_product_tier($p, $o->ingredients, 'ingredient', $o->sku);
     $this->import_product_tier($p, $o->goals, 'goal', $o->sku);
     ProductSupplier::where('product_id', $p->id)->delete();
     $this->import_product_supplier($p, $o->suppliers, $o->sku);
 }