/** * @param float|integer $value * @param ProductUnit $unit * @param boolean $isShort * @return string */ protected function formatData($value, ProductUnit $unit, $isShort = false) { if (!is_numeric($value)) { throw new \InvalidArgumentException(sprintf('The parameter "value" must be a numeric, but it is of type %s.', gettype($value))); } $translationKey = sprintf('orob2b.product_unit.%s.value.' . ($isShort ? 'short' : 'full'), $unit->getCode()); return $this->translator->transChoice($translationKey, $value, ['%count%' => $value]); }
/** * @param Product $product * @param ProductUnit $productUnit * @param float $quantity */ public function __construct(Product $product, ProductUnit $productUnit, $quantity) { if (!$product->getId()) { throw new \InvalidArgumentException('Product must have id.'); } $this->product = $product; if (!$productUnit->getCode()) { throw new \InvalidArgumentException('ProductUnit must have code.'); } $this->productUnit = $productUnit; if (!is_numeric($quantity) || $quantity < 0) { throw new \InvalidArgumentException('Quantity must be numeric and more than or equal zero.'); } $this->quantity = $quantity; }
/** * Set productUnit * * @param ProductUnit $productUnit * @return $this */ public function setProductUnit(ProductUnit $productUnit = null) { $this->productUnit = $productUnit; if ($productUnit) { $this->productUnitCode = $productUnit->getCode(); } return $this; }
/** * Set productUnit * * @param ProductUnit $productUnit * @return $this */ public function setProductUnit(ProductUnit $productUnit = null) { if ($productUnit && (!$this->productUnit || $productUnit->getCode() !== $this->productUnit->getCode())) { $this->requirePriceRecalculation = true; } $this->productUnit = $productUnit; return $this; }