/** * @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); }
/** * @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; }
/** * 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(); }