public function testAcceptingAProductDeactivation()
 {
     $notification = new GammaNotification(['product_id' => 1, 'account_id' => 1, 'brand_id' => 1, 'category_id' => 1, 'type' => 'deactivate']);
     $notification->save();
     $this->expectsJobs([DeactivateProduct::class, CleanupDetail::class]);
     $job = new AcceptGammaNotification($notification);
     $this->handleJob($job);
 }
 /**
  * @param GammaNotification $notifications
  */
 public function handle(GammaNotification $notifications)
 {
     $processingOrExisting = $notifications->where('category_id', $this->category->id)->count();
     if ($processingOrExisting) {
         $message = "can't deactivate, something is still being processed";
         abort(400, $message, ['statustext' => $message]);
     }
     if ($this->category->selection) {
         $this->category->selection->delete();
     }
 }
Beispiel #3
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;
 }
 public function startData()
 {
     $account1 = factory(Account::class)->create();
     $digiredo = Account::find(1);
     $account2 = factory(Account::class)->create();
     $category = factory(Category::class)->create();
     $brand = factory(Brand::class)->create();
     //create 3 products, but all a different account
     factory(Product::class)->create(['brand_id' => $brand->id, 'account_id' => $account1->id]);
     $notSee = factory(Product::class)->create(['brand_id' => $brand->id, 'account_id' => $account2->id]);
     factory(Product::class)->create(['brand_id' => $brand->id, 'account_id' => $digiredo->id]);
     //create notification
     $notification = new GammaNotification(['account_id' => $account1->id, 'brand_id' => $brand->id, 'category_id' => $category->id, 'type' => 'activate']);
     $notification->save();
     return [$category->id, $account1->id, $brand->id, $notification, $notSee];
 }
 /**
  * @param GammaNotification $notifications
  * @param $status
  */
 protected function cancelNotifications(GammaNotification $notifications, $status)
 {
     $existing = $notifications->whereNotNull('product_id')->notBeingProcessed()->where('category_id', $this->notification->category->id)->where('brand_id', $this->notification->brand->id)->where('type', $status)->get();
     foreach ($existing as $notification) {
         $notification->delete();
     }
 }
 /**
  * @param GammaNotification $notification
  * @param Account $account
  * @param Brand $brand
  * @param Category $category
  * @return
  */
 protected function findExistingCombination(GammaNotification $notification, Account $account, Brand $brand, Category $category)
 {
     $existing = $notification->newQueryWithoutScopes()->where('account_id', $account->id)->where('brand_id', $brand->id)->where('category_id', $category->id)->notBeingProcessed()->first();
     return $existing;
 }
 /**
  * @param GammaNotification $notification
  * @param $brand
  * @param $category
  * @return
  */
 protected function findExistingCombination(GammaNotification $notification, $brand, $category)
 {
     $existing = $notification->where('brand_id', $brand->id)->where('category_id', $category->id)->first();
     return $existing;
 }
 /**
  * @param GammaNotification $notification
  * @param $field
  * @param $ids
  * @return mixed
  */
 protected function reviews(GammaNotification $notification, $field, $ids)
 {
     $reviews = $notification->whereIn($field, $ids)->whereNull('product_id')->get()->groupBy($field);
     return $reviews;
 }