/** * @param GammaSelection $gamma */ protected function denyDeactivation(GammaSelection $gamma) { //when denying a deactivating of a product, we need to make sure the combination is still selected $exists = $gamma->where('category_id', $this->notification->category->id)->where('brand_id', $this->notification->brand->id)->first(); if (!$exists) { $gamma->create(['account_id' => $this->notification->account_id, 'brand_id' => $this->notification->brand_id, 'category_id' => $this->notification->category_id]); } }
/** * @param GammaSelection $gamma * @param ProductSelection $products * @param GammaNotification $notifications */ public function handle(GammaSelection $gamma, ProductSelection $products, GammaNotification $notifications) { if ($this->shouldNotRun($products, $notifications)) { return; } $selections = $products->newQueryWithoutScopes()->join('product_gamma_categories', 'product_gamma_categories.selection_id', '=', 'product_gamma.id')->where('account_id', $this->account->id)->where('brand_id', $this->brand->id)->where('category_id', $this->category->id)->get(['product_gamma.*']); foreach ($selections as $selection) { $selections->load(['categories' => function ($query) { $query->withTrashed(); }]); foreach ($selection->categories as $category) { $category->forceDelete(); } $selection->forceDelete(); } $selections = $gamma->newQueryWithoutScopes()->where(['account_id' => $this->account->id, 'brand_id' => $this->brand->id, 'category_id' => $this->category->id])->get(); foreach ($selections as $selection) { $selection->delete(); } }
/** * @param GammaSelection $gamma * @param $notification */ protected function deleteExistingGammaSelection(GammaSelection $gamma, $notification) { $selections = $gamma->where(['category_id' => $notification->category->id, 'brand_id' => $notification->brand->id])->get(); foreach ($selections as $selection) { $selection->delete(); } }
/** * @param GammaSelection $gamma * @param $field * @param $ids * @return mixed */ protected function selections(GammaSelection $gamma, $field, $ids) { $selections = $gamma->whereIn($field, $ids)->get()->groupBy($field); return $selections; }
/** * @param GammaSelection $gamma */ protected function insertGamma(GammaSelection $gamma) { //insert this as a gamma selection $selected = $gamma->newInstance(['category_id' => $this->category->id, 'brand_id' => $this->brand->id, 'account_id' => $this->account->id]); $selected->save(); }