Пример #1
0
 /**
  * Shop home.
  *
  *
  */
 public function index()
 {
     $products = Product::with(['translations', 'images', 'images.translations'])->take(15)->get();
     $latest = $this->section($products, 4);
     $top = $this->section($products, 3);
     $bestsellers = $this->section($products, 3);
     $sales = $this->section($products, 3);
     $featured = $products;
     $tweets = latest_tweets_about(4);
     return $this->theme->render('shop.store', ['latest' => $latest, 'featured' => $featured, 'sales' => $sales, 'bestsellers' => $bestsellers, 'top' => $top, 'tweets' => $tweets]);
 }
Пример #2
0
 protected function properties(Product $product, Category $category)
 {
     $properties = Property::where('category_id', $category->id)->get();
     $properties = $properties->random(rand(5, 10));
     $values = new Collection();
     foreach ($properties as $property) {
         $payload = ['property_id' => $property->id];
         if ($property->options->count()) {
             $payload['option_id'] = $property->options->random(1)->id;
         }
         $values->push(factory(PropertyValue::class)->make($payload));
     }
     $product->properties()->saveMany($values);
 }
 public function testReviewingBatchActivation()
 {
     list($category_id, $account_id, $brand_id, $notification, $otherProduct) = $this->startData();
     $job = new ReviewGammaNotification($notification);
     $this->handleJob($job);
     //new account -> should not contain actual gamma
     // -> should have the selection
     // -> should have the notifications for products within the subscribed accounts
     $subscriptions = app('Modules\\Shop\\Gamma\\GammaSubscriptionManager');
     $products = Product::where('brand_id', $brand_id)->whereHas('categories', function ($q) use($category_id) {
         $q->where('category_id', $category_id);
     })->whereIn('account_id', $subscriptions->subscribedIds(Account::find($account_id)));
     foreach ($products as $product) {
         $this->seeInDatabase('product_gamma_notifications', ['product_id' => $product->id, 'brand_id' => $product->brand_id, 'category_id' => $category_id, 'account_id' => $account_id, 'type' => 'activate']);
         $this->notSeeInDatabase('product_gamma', ['product_id' => $product->id, 'account_id' => $account_id]);
     }
     $this->notSeeInDatabase('product_gamma_notifications', ['product_id' => $otherProduct->id, 'brand_id' => $otherProduct->brand_id, 'category_id' => $category_id, 'account_id' => $account_id, 'type' => 'activate']);
     $this->seeInDatabase('product_gamma_selections', ['account_id' => $account_id, 'category_id' => $category_id, 'brand_id' => $brand_id]);
     $this->notSeeInDatabase('product_gamma_notifications', ['id' => $notification->id]);
 }
Пример #4
0
 /**
  * @param Product $product
  * @param PropertyUnit $unit
  */
 protected function prepareProperties(Product $product, PropertyUnit $unit)
 {
     $category = $product->mainCategory();
     if ($category) {
         $category->load(['propertyGroups', 'propertyGroups.translations', 'properties', 'properties.translations']);
         $product->propertyGroups = $category->propertyGroups;
         $product->propertyProperties = $category->properties->groupBy('group_id');
         foreach ($product->propertyGroups as $group) {
             if (!$product->propertyProperties->has($group->id)) {
                 //make sure we can add to empty groups
                 $product->propertyProperties->put($group->id, new Collection());
             }
         }
         $product->propertyUnits = $unit->with('translations')->get()->keyBy('id');
         $propertyIds = $category->properties->lists('id')->toArray();
         if (count($propertyIds)) {
             $product->propertyOptions = PropertyOption::with(['translations'])->whereIn('property_id', $propertyIds)->get()->groupBy('property_id');
             $product->propertyOptions = $product->propertyOptions->map(function ($item) {
                 return $item->keyBy('id');
             });
         } else {
             $product->propertyOptions = new Collection();
         }
         $product->hasMainCategory = true;
         $product->setRelation('properties', $product->properties->keyBy('property_id'));
     }
 }
Пример #5
0
 /**
  * @return bool|Product
  */
 public function handle()
 {
     $this->product->fill($this->input);
     return $this->product->save() ? $this->product : false;
 }
Пример #6
0
 /**
  * @param $account
  * @param $brand
  * @param $data
  * @param $category
  * @return static
  */
 protected function productBase($account, $brand, $data, $category)
 {
     $product = Product::create(['account_id' => $account->id, 'brand_id' => $brand, 'nl' => ['name' => $data->name, 'title' => $data->product_title, 'content' => $data->description], 'en' => ['name' => $data->name]]);
     $product->categories()->save($category);
     return $product;
 }
 /**
  * @param Request $request
  * @param Product $product
  */
 public function batchUnpublish(Request $request, Product $product)
 {
     $ids = $request->get('products', []);
     if (is_array($ids) && count($ids)) {
         $products = $product->whereIn('products.id', $ids)->get();
         foreach ($products as $product) {
             $translation = $product->translate($request->get('locale'));
             if ($translation) {
                 $translation->published = false;
             }
             $translation->save();
         }
     }
 }
Пример #8
0
 /**
  * @param $product
  * @param $category_id
  * @return bool
  */
 protected function combinationStillExists($product, $category_id)
 {
     $count = $this->product->newQueryWithoutScopes()->join('product_categories_pivot', 'product_categories_pivot.product_id', '=', 'products.id')->where('category_id', $category_id)->where('brand_id', $product['brand_id'])->count();
     return $count > 0;
 }
 /**
  * @return array
  */
 protected function setupForDeactivation($use_product)
 {
     list($account_id, $brand_id, $category_id, $notification) = $this->startData($use_product, 'deactivate');
     $products = Product::where(['brand_id' => $brand_id])->get();
     $this->database(new GammaSelection())->insert(['account_id' => $account_id, 'brand_id' => $brand_id, 'category_id' => $category_id]);
     foreach ($products as $product) {
         $id = $this->database(new ProductSelection())->insertGetId(['account_id' => $account_id, 'brand_id' => $brand_id, 'product_id' => $product->id]);
         $this->database(new ProductCategorySelection())->insert(['selection_id' => $id, 'category_id' => $category_id]);
     }
     return [$account_id, $brand_id, $category_id, $notification, $products];
 }