/**
  * @param ProductSelection $productGamma
  * @return mixed
  */
 protected function loadSelections(ProductSelection $productGamma)
 {
     $selections = $productGamma->chunkActiveProducts($this->brand->id, $this->category->id, $this->account->id);
     $selections->load(['categories' => function ($query) {
         $query->withTrashed();
     }]);
     return $selections;
 }
예제 #2
0
 /**
  * @param ProductSelection $products
  * @param GammaNotification $notifications
  * @return bool
  */
 protected function shouldNotRun(ProductSelection $products, GammaNotification $notifications)
 {
     if ($products->countActiveProducts($this->brand->id, $this->category->id, $this->account->id) > 0) {
         return true;
     }
     $payload = ['brand_id' => $this->brand->id, 'category_id' => $this->category->id];
     if ($notifications->where($payload)->count()) {
         return true;
     }
     return false;
 }
 /**
  * @param Request $request
  * @param ProductSelection $selections
  * @param SearchServiceInterface $search
  * @param Product $products
  * @param AccountManager $account
  * @return mixed
  */
 public function index(Request $request, ProductSelection $selections, SearchServiceInterface $search, Product $products, AccountManager $account, IndexManager $indexer)
 {
     $account = $account->account();
     //bazinga, we can now fully search using elasticsearch.
     //we don't care about the nearly realtime
     //even a minute would be acceptable, for blazing fast sites.
     //allright
     $indexes = $account->alias;
     $query = ['index' => $indexes, 'type' => $selections->getSearchableType(), 'body' => ['query' => ['filtered' => ['query' => ['match_all' => new \StdClass()]]]]];
     $relations = ['product', 'product.translations', 'product.images', 'product.images.sizes' => function ($query) {
         $query->dimension(150);
     }, 'product.brand', 'product.brand.translations'];
     $result = $search->search($selections->getSearchableType(), $query, $relations);
     return $result;
 }
 /**
  * @param CatalogRepositoryInterface $catalog
  * @param ProductSelection $selections
  * @param $status
  */
 protected function notifyWithinScope(CatalogRepositoryInterface $catalog, ProductSelection $selections, $status)
 {
     $notification = $this->notification;
     $callback = function ($products) use($notification, $selections, $status) {
         $records = $selections->newQueryWithoutScopes()->where('account_id', $notification->account_id)->whereIn('product_id', $products->lists('id')->toArray())->get()->keyBy('product_id');
         foreach ($products as $product) {
             $notificationPayload = ['product_id' => $product->id, 'category_id' => $notification->category->id, 'brand_id' => $notification->brand->id, 'account_id' => $notification->account->id, 'type' => $status];
             $record = $records->get($product->id);
             //when notifying, we do not want to generate a warning for something that's already in that status.
             if ($status == 'activate' && (!$record || $record->deleted_at)) {
                 $notification->create($notificationPayload);
             } elseif ($status == 'deactivate' && ($record && !$record->deleted_at)) {
                 $notification->create($notificationPayload);
             }
         }
     };
     $catalog->chunkWithinBrandCategory($notification->account, $notification->brand, $notification->category, $callback);
 }
예제 #5
0
 /**
  * @param ProductSelection $base
  * @return
  */
 protected function existingCategorySelection(ProductSelection $base)
 {
     $selection = $base->categories()->where('category_id', $this->category->id)->withTrashed()->first();
     return $selection;
 }
 /**
  * @param ProductSelection $instance
  * @return bool
  */
 protected function otherCategories(ProductSelection $instance)
 {
     $query = $instance->newQueryWithoutScopes();
     $query->join('product_gamma_categories', 'product_gamma_categories.selection_id', '=', 'product_gamma.id')->where('product_gamma.id', $instance->id);
     return $query->count() == 0;
 }
예제 #7
0
 /**
  * do the query manually, so we won't depend on account manager.
  * if this ever get's called in a global system context,
  * it will now still work.
  *
  * @param ProductSelection $selection
  * @return \Illuminate\Database\Eloquent\Model|null|static
  */
 protected function getExisting(ProductSelection $selection)
 {
     return $selection->newQueryWithoutScopes()->where('account_id', $this->account->id)->where('product_id', $this->product->id)->where('brand_id', $this->product->brand_id)->first();
 }