Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * @param ProductSelection $productGamma
  */
 public function handle(ProductSelection $productGamma)
 {
     //chunk alike thinking here
     while ($productGamma->countActiveProducts($this->brand->id, $this->category->id, $this->account->id) > 0) {
         $selections = $this->loadSelections($productGamma);
         foreach ($selections as $selection) {
             $category = $selection->categories->first(function ($key, $item) {
                 return $item->category_id == $this->category->id;
             });
             $category->delete();
             $active = $selection->categories->filter(function ($item) {
                 return !$item->trashed();
             });
             if ($active->count() == 0) {
                 $selection->delete();
             }
         }
     }
 }