Skip to content

Instantly share code, notes, and snippets.

@iZaL
Created October 10, 2016 09:21
Show Gist options
  • Select an option

  • Save iZaL/9a464bf9808db4a1b984b679fa6c4100 to your computer and use it in GitHub Desktop.

Select an option

Save iZaL/9a464bf9808db4a1b984b679fa6c4100 to your computer and use it in GitHub Desktop.
public function addItem(Requests\Frontend\addProductToCart $request)
{
if ($this->cart->getItemsCount() > 1) {
$product = $this->productRepository->model->with('parent')->find($request->product_id);
$parentCategory = $product->parent->first();
$cartItemIds = $this->cart->getItems()->pluck('id')->toArray();
if ($parentCategory->limited) {
$cartProducts = $this->productRepository->model->with('parent')->whereIn('id', $cartItemIds)->get();
$parentCategories = $cartProducts->pluck('parent')->flatten();
$categoryItems = $parentCategories->where('id', $parentCategory->id)->count();
if ($categoryItems >= 2) {
return redirect()->route('cart.index')->with('error', trans('general.messages.error.cart.perfumes'));
}
}
}
$this->cart->addItem([
'id' => $request->product_id,
'quantity' => (int)$request->quantity,
'product_attribute_id' => (int)$request->product_attribute_id]
);
return redirect()->route('cart.index')->with('success', trans('cart.updated'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment