sEnte Posted June 19, 2016 at 11:09 PM Report #597287 Posted June 19, 2016 at 11:09 PM Ainda continuando com a mesma app.... No carrinho de compras o que queria fazer é o seguinte, na lista de produtos selecciona-se um produto e faz-se adicionar. Até aqui tudo bem, quando tento adicionar mais que um produto da mesma coisa deveria ser incrementado, mas não é. atualmente é isto que tenho <?php namespace Cart\Basket; use Cart\Models\Product; use Cart\Support\Storage\Contracts\StorageInterface; use Cart\Basket\Exceptions\QuantityExceededException; class Basket { protected $storage; protected $product; public function __construct(StorageInterface $storage, Product $product) { $this->storage = $storage; $this->product = $product; } public function add(Product $product, $quantity) { if ($this->has($product)) { $quantity = $this->get($product)['quantity'] + $quantity; } $this->update($product, $quantity); } public function update(Product $product, $quantity) { if (!$this->product->find($product->id)->hasStock($quantity)) { throw new QuantityExceededException; } if ($quantity === 0) { $this->remove($product); return; } $this->storage->set($product->id, [ 'product_id' => (int) $product->id, 'quantity' => (int) $quantity, ]); } "If It Ain't Broke, Break it and build something Cooler!" Unknown
HappyHippyHippo Posted June 19, 2016 at 11:20 PM Report #597290 Posted June 19, 2016 at 11:20 PM isso depende do funcionamento desta função : $this->storage->set($product->id, [ 'product_id' => (int) $product->id, 'quantity' => (int) $quantity, ]); lembra-te que nunca disseste que biblioteca éssa "Cart" IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
sEnte Posted June 19, 2016 at 11:41 PM Author Report #597292 Posted June 19, 2016 at 11:41 PM (edited) Ã idea é ir à BD buscar os campos referentes à id e a quantidade foi o nome que dei quando comecei. { "require": { "slim/slim": "^3.0", "slim/twig-view": "^2.1", "php-di/slim-bridge": "^1.0", "illuminate/database": "^5.2" }, "autoload": { "psr-4": { "Cart\\": "app" } } } e estas são as libraries que estou a usar. Edited June 19, 2016 at 11:50 PM by sEnte "If It Ain't Broke, Break it and build something Cooler!" Unknown
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now