/** * Populate this item with the data from a specific unit. * * @param Unit $unit The unit to populate from * * @return Item Returns $this for chainability */ public function populate(Unit $unit) { $product = $unit->getProduct(); if ($this->order instanceof Order) { $this->listPrice = $unit->getPrice('retail', $this->order->currencyID); $this->rrp = $unit->getPrice('rrp', $this->order->currencyID); $this->actualPrice = $this->actualPrice ?: $this->listPrice; } $this->productTaxRate = (double) $product->getTaxRates()->getTotalTaxRate(); $this->taxStrategy = $product->getTaxStrategy()->getName(); $this->productID = $product->id; $this->productName = $product->name; $this->unitID = $unit->id; $this->unitRevision = $unit->revisionID; $this->sku = $unit->sku; $this->barcode = $unit->barcode; $this->options = implode($unit->options, ', '); $this->brand = $product->brand; $this->weight = (int) $unit->weight; $this->_taxes = []; foreach ($product->getTaxRates() as $taxRate) { $this->_taxes[$taxRate->getType()] = $taxRate->getRate(); } return $this; }
/** * {@inheritDoc} */ public function getProduct() { if ($this->_productID && !parent::getProduct() && $this->_loaders->exists('product')) { $product = $this->_loaders->get('product')->getByID($this->_productID); $this->setProduct($product); } return parent::getProduct(); }