/** * Sets the quantity of a purchasable object on the Purchasable holder * @param \Heystack\Ecommerce\Purchasable\Interfaces\PurchasableInterface $purchasable The purchasable object * @param int $quantity quantity of the purchasable object to be set * @return void */ public function setPurchasable(PurchasableInterface $purchasable, $quantity) { $this->assertValidQuantity($quantity); $identifier = $purchasable->getIdentifier(); // If already in the holder if ($this->hasPurchasable($identifier)) { $this->changePurchasableQuantity($this->getPurchasable($identifier), $quantity); } else { $purchasable->addStateService($this->stateService); $purchasable->addEventService($this->eventService); $purchasable->setQuantity($quantity); $purchasable->setUnitPrice($purchasable->getPrice()); $this->purchasables[$identifier->getFull()] = $purchasable; $this->updateTotal(); $this->eventService->dispatch(Events::PURCHASABLE_ADDED); } }
/** * @param \SS_HTTPRequest $request * @param \Heystack\Ecommerce\Purchasable\Interfaces\PurchasableInterface $purchasable * @return array */ protected function removePurchasable(\SS_HTTPRequest $request, PurchasableInterface $purchasable) { $this->purchasableHolder->removePurchasable($purchasable->getIdentifier()); return $this->succeeded($purchasable); }