Exemplo n.º 1
0
 /**
  * @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();
     }
 }
Exemplo n.º 3
0
 public function equals(ProductInterface $product)
 {
     return $this->id == $product->getId();
 }
Exemplo n.º 4
0
 public function getSearchTerms(ProductInterface $product)
 {
     $data = array();
     $data['name'] = $product->getName();
     return $data;
 }
Exemplo n.º 5
0
 /**
  * @param ProductInterface $product
  * @param string $code
  */
 public function setProductSKU(ProductInterface $product, $code)
 {
     $sku = new SKUIdentifier();
     $sku->setCode($code);
     $product->addIdentifier($sku);
 }
Exemplo n.º 6
0
 /**
  * @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);
     }
 }