/**
  * @param CatalogRepositoryInterface $catalog
  * @param GammaSelection $gamma
  */
 public function handle(CatalogRepositoryInterface $catalog, GammaSelection $gamma)
 {
     $this->insertGamma($gamma);
     $catalog->chunkWithinBrandCategory($this->account, $this->brand, $this->category, function ($products) {
         foreach ($products as $product) {
             $this->dispatch(new ActivateProduct($product, $this->category, $this->account));
         }
     });
 }
 /**
  * @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);
 }