/** * @inheritdoc */ function updateProduct(ProductInterface $product, $andFlush = false) { $id = $product->getId(); if (null == $id) { $id = uniqid(); $rp = new \ReflectionProperty($product, 'id'); $rp->setAccessible(true); $rp->setValue($product, $id); $rp->setAccessible(false); } $this->products[$id] = $product; }
/** * @inheritdoc */ public function updateProduct(ProductInterface $product, $andFlush = false) { //Assure a product parent exists, if it doesn't exists use the first taxonomy node as parent if (null == $product->getParent()) { foreach ($product->getTaxonomies() as $taxonomyNode) { $product->setParent($taxonomyNode); break; } } $this->dm->persist($product); if ($andFlush) { $this->flush(); } }
public function equals(ProductInterface $product) { return $this->id == $product->getId(); }
public function getSearchTerms(ProductInterface $product) { $data = array(); $data['name'] = $product->getName(); return $data; }
/** * @param ProductInterface $product * @param string $code */ public function setProductSKU(ProductInterface $product, $code) { $sku = new SKUIdentifier(); $sku->setCode($code); $product->addIdentifier($sku); }
/** * @inheritdoc */ public function findProductInOrder(OrderInterface $cart, ProductInterface $product, array $options = null) { if ($items = $cart->getItems()) { foreach ($cart->getItems() as $item) { if ($product->equals($item->getProduct())) { if ($this->doOptionsMatch($item->getOptions(), $options)) { return $item; } } } } return null; }
protected function buildProductPrices(ProductInterface $product, $defaultTaxRate) { /** Set up for each product following pricing elements * - unit : unit price without tax * - unitMSRP: manufacturer suggested retail price without tax * - unitTax : tax over the net unit price (based on the default tax rate) * - unitTotal: final price a customer pays ( net unit price + tax ) * - unitMSRPTotal: manufacturer suggested retail price with tax **/ $pricingValues = array(); $pricingValues['unit'] = rand(2, 80); // Set Manufacturer Suggested Retail Price to +(random) % of the net unit price $pricingValues['MSRPDiscountRate'] = rand(10, 35); $pricingValues['unitMSRP'] = $pricingValues['unit'] * (1 + $pricingValues['MSRPDiscountRate'] / 100); if ($defaultTaxRate) { $pricingValues['unitTax'] = $pricingValues['unit'] / 100 * $defaultTaxRate; $pricingValues['unitMSRPTotal'] = $pricingValues['unitMSRP'] * (1 + $defaultTaxRate / 100); $pricingValues['unitTotal'] = $pricingValues['unit'] + $pricingValues['unitTax']; } else { $pricingValues['unitTotal'] = $pricingValues['unit']; $pricingValues['unitMSRPTotal'] = $pricingValues['unitMSRP']; } foreach ($pricingValues as $type => $value) { $product->setPrice($value, $type); } }