Created
October 10, 2016 09:21
-
-
Save iZaL/9a464bf9808db4a1b984b679fa6c4100 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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