/** * 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(); }
/** * @param string | array $data Product data submitted by form * @throws TransformationFailedException Exception thrown if invalid type given * * @return Product Returns instance of Product object */ public function reverseTransform($data) { $product = new Product($this->_locale, $this->_priceTypes, $this->_defaultCurrency, $this->_taxStrategy); $product->setName($data['name'])->setDisplayName($data['name'])->setBrand($data['brand'])->setCategory($data['category'])->setDescription($data['description'])->setType($this->_productTypes->get($data['type'])); // setting prices foreach ($data['prices']['currencies'] as $currency => $typePrices) { foreach ($typePrices as $type => $price) { $product->setPrice($type, $currency, $price); } } // create the unit if (!empty($data['units'])) { foreach ($data['units'] as $unitData) { $unit = new Unit($this->_locale, $this->_priceTypes, $this->_defaultCurrency); $unit->setProduct($product); $unit->setSKU($unitData['sku']); $unit->setStockForLocation($unitData['stock'], $this->_defaultLocation); $unit->setVisible(true); $unit->revisionID = 1; foreach ($unitData['variants'] as $option) { $unit->setOption($option['key'], $option['value']); } $product->addUnit($unit); } } return $product; }
/** * Creates an adjustment for the given unit and location, with a new * value the stock level will be set to. * No conversion into a positive value will be made! * * @param Unit $unit the unit the adjustment will effect * @param Location $location the stock location * @param int $value the new stock level * * @throws \IllegalArgumentException if the value is negative * * @return StockManager $this for chainability */ public function set(Unit $unit, Location $location, $value) { if ($value < 0) { throw new \IllegalArgumentException("Value set for stock adjustment must be positive!"); } $adjustment = new Adjustment\Adjustment(); $curStockLevel = $unit->getStockForLocation($location); $adjustment->unit = $unit; $adjustment->location = $location; $adjustment->delta = $value - $curStockLevel; $this->_saveNewAdjustment($adjustment); return $this; }
public function create(Product\Product $product, array $options = [], Product\Unit\Unit $unit = null, $variantName = null) { if ($unit && !$variantName) { throw new \LogicException('You must set a variant name to make pages for individual variants'); } $options = $options + $this->_defaults; if (empty($options[Options::CREATE_PAGES])) { return false; } $variantValue = $unit ? $unit->getOption($variantName) : null; if (!$this->_allowDuplicates && $this->_exists->exists($product, $variantName, $variantValue)) { return false; } $page = $this->_getNewProductPage($product, $this->_getParentPage($product, $options), $variantValue); $page->publishDateRange = new DateRange(new \DateTime()); $this->_setProductPageContent($page, $product, $options, $variantName, $variantValue); return $this->_dispatcher->dispatch($page, $product, $options[Options::CSV_PORT], $unit); }
private function _getProductPrice($type, $currency) { return (double) $this->_unit->getPrice($type, $currency); }
/** * Set the return item from a ProductUnit. * * @param ProductUnit $unit * @return Assembler */ public function setReturnItemFromProductUnit(ProductUnit $unit) { $this->_return->item = $returnItem = new OrderReturnItem(); $retailPrice = $unit->getPrice('retail', $this->_currencyID); $rrpPrice = $unit->getPrice('rrp', $this->_currencyID); $returnItem->listPrice = $retailPrice; $returnItem->actualPrice = $retailPrice; $returnItem->returnedValue = $retailPrice; $returnItem->calculatedBalance = 0 - $retailPrice; $returnItem->rrp = $rrpPrice; $returnItem->productTaxRate = (double) $unit->product->taxRate; $returnItem->taxStrategy = $unit->product->taxStrategy; $returnItem->productID = $unit->product->id; $returnItem->productName = $unit->product->name; $returnItem->unit = $unit; $returnItem->unitID = $unit->id; $returnItem->unitRevision = $unit->revisionID; $returnItem->sku = $unit->sku; $returnItem->barcode = $unit->barcode; $returnItem->options = implode($unit->options, ', '); $returnItem->brand = $unit->product->brand; $returnItem->status = $this->_defaultStatus; $address = $this->_return->getPayableAddress('delivery') ?: $this->_defaultAddress; $taxRates = $this->_taxLoader->getProductTaxRates($unit->product, $address); foreach ($taxRates as $rate) { $returnItem->taxes[$rate->getType()] = $rate->getRate(); } $this->_calculateTax($returnItem); return $this; }
/** * Returns the last stock-level in the stock-history, using the internal * $_counter-array. * Uses _checkUnitsSet-method to make sure a product was already set! * * @return int last stock level, if never adjusted the current stock level is returned */ public function getLastStock(Unit $unit, Location\Location $location) { $this->_checkUnitsSet(); if (!isset($this->_counter[$unit->id][$location->name])) { $this->_counter[$unit->id][$location->name] = $unit->getStockForLocation($location); } return $this->_counter[$unit->id][$location->name]; }
public function saveStockForLocation(Unit $unit, Location $location) { return $this->_saveStockLevel($unit->id, $location->name, $unit->getStockForLocation($location)); }