/** * @covers Mage_Catalog_Model_Product::addCustomOption * @covers Mage_Catalog_Model_Product::setCustomOptions * @covers Mage_Catalog_Model_Product::getCustomOptions * @covers Mage_Catalog_Model_Product::getCustomOption * @covers Mage_Catalog_Model_Product::hasCustomOptions */ public function testCustomOptionsApi() { $this->assertEquals(array(), $this->_model->getCustomOptions()); $this->assertFalse($this->_model->hasCustomOptions()); $this->_model->setId(99); $this->_model->addCustomOption('one', 'value1'); $option = $this->_model->getCustomOption('one'); $this->assertInstanceOf('Varien_Object', $option); $this->assertEquals($this->_model->getId(), $option->getProductId()); $this->assertSame($option->getProduct(), $this->_model); $this->assertEquals('one', $option->getCode()); $this->assertEquals('value1', $option->getValue()); $this->assertEquals(array('one' => $option), $this->_model->getCustomOptions()); $this->assertTrue($this->_model->hasCustomOptions()); $this->_model->setCustomOptions(array('test')); $this->assertTrue(is_array($this->_model->getCustomOptions())); }
/** * Check product representation in item * * @param Mage_Catalog_Model_Product $product * @return bool */ public function representProduct($product) { $itemProduct = $this->getProduct(); if (!$product || $itemProduct->getId() != $product->getId()) { return false; } /** * Check maybe product is planned to be a child of some quote item - in this case we limit search * only within same parent item */ $stickWithinParent = $product->getStickWithinParent(); if ($stickWithinParent) { if ($this->getParentItem() !== $stickWithinParent) { return false; } } // Check options $itemOptions = $this->getOptionsByCode(); $productOptions = $product->getCustomOptions(); if (!$this->compareOptions($itemOptions, $productOptions)) { return false; } if (!$this->compareOptions($productOptions, $itemOptions)) { return false; } return true; }
/** * Check product representation in item * * @param Mage_Catalog_Model_Product $product * @return bool */ public function representProduct($product) { $itemProduct = $this->getProduct(); if ($itemProduct->getId() != $product->getId()) { return false; } $itemOptions = $this->getOptionsByCode(); $productOptions = $product->getCustomOptions(); if (!$this->compareOptions($itemOptions, $productOptions)) { return false; } if (!$this->compareOptions($productOptions, $itemOptions)) { return false; } return true; }
function _productToOrderItem(Mage_Catalog_Model_Product $product, $qty = 1) { $rowTotal = $product->getFinalPrice() * $qty; $options = $product->getCustomOptions(); $optionsByCode = array(); foreach ($options as $option) { $quoteOption = Mage::getModel('sales/quote_item_option')->setData($option->getData())->setProduct($option->getProduct()); $optionsByCode[$quoteOption->getCode()] = $quoteOption; } $product->setCustomOptions($optionsByCode); $options = $product->getTypeInstance(true)->getOrderOptions($product); $orderItem = Mage::getModel('sales/order_item')->setStoreId($this->_storeId)->setQuoteItemId(0)->setQuoteParentItemId(NULL)->setProductId($product->getId())->setProductType($product->getTypeId())->setQtyBackordered(NULL)->setTotalQtyOrdered($product['rqty'])->setQtyOrdered($product['qty'])->setName($product->getName())->setSku($product->getSku())->setPrice($product->getFinalPrice())->setBasePrice($product->getFinalPrice())->setOriginalPrice($product->getFinalPrice())->setRowTotal($rowTotal)->setBaseRowTotal($rowTotal)->setWeeeTaxApplied(serialize(array()))->setBaseWeeeTaxDisposition(0)->setWeeeTaxDisposition(0)->setBaseWeeeTaxRowDisposition(0)->setWeeeTaxRowDisposition(0)->setBaseWeeeTaxAppliedAmount(0)->setBaseWeeeTaxAppliedRowAmount(0)->setWeeeTaxAppliedAmount(0)->setWeeeTaxAppliedRowAmount(0)->setProductOptions($options); $this->_subTotal += $rowTotal; return $orderItem; }
/** * add product in order * * @param Mage_Catalog_Model_Product $product * @param int $qty * @param $price * @return Mage_Sales_Model_Order_Item */ function _productToOrderItem(Mage_Catalog_Model_Product $product, $qty = 1, $price) { $options = $product->getCustomOptions(); $optionsByCode = array(); $bundleOptSelAttr = null; foreach ($options as $option) { $quoteOption = Mage::getModel('sales/quote_item_option')->setData($option->getData())->setProduct($option->getProduct()); if ($quoteOption->getCode() == 'bundle_selection_attributes') { $bundleOptSelAttr = $quoteOption->getValue(); } $optionsByCode[$quoteOption->getCode()] = $quoteOption; } $product->setCustomOptions($optionsByCode); // DECREMENTE O STOCK $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId()); if ($stockItem->getManageStock()) { $stockItem->setData('qty', $stockItem->getQty() - $product['cart_qty']); } $stockItem->save(); $options = $product->getTypeInstance(true)->getOrderOptions($product); if ($bundleOptSelAttr != null) { $options['bundle_selection_attributes'] = $bundleOptSelAttr; } $finalPrice = $price; if ($product['parent_product_id']) { $productParent = Mage::getModel('catalog/product')->load($product['parent_product_id']); if ($productParent->getTypeID() == "bundle" && $productParent->getPriceType() == 0) { //GET PROC FROM REAL PRICE $priceModel = $productParent->getPriceModel(); $PriceBundle = $priceModel->getTotalPrices($productParent, null, true, false); $PriceBundle = reset($PriceBundle); $priceProdCur = $product->getFinalPrice(); $currPorc = 100 * $priceProdCur / $PriceBundle; $finalPrice = $currPorc * $price / 100; } } $qtdOrdered = $product['cart_qty']; if ($product->getTypeID() == "bundle") { $rowTotal = 0; } else { $rowTotal = $finalPrice * $qty; } $orderItem = Mage::getModel('sales/order_item')->setStoreId($this->_storeId)->setQuoteItemId(0)->setQuoteParentItemId(NULL)->setProductId($product->getId())->setProductType($product->getTypeId())->setQtyBackordered(NULL)->setTotalQtyOrdered($product['rqty'])->setQtyOrdered($qtdOrdered)->setName($product->getName())->setSku($product->getSku())->setPrice($finalPrice)->setBasePrice($finalPrice)->setOriginalPrice($product->getFinalPrice())->setRowTotal($rowTotal)->setBaseRowTotal($rowTotal)->setWeeeTaxApplied(serialize(array()))->setBaseWeeeTaxDisposition(0)->setWeeeTaxDisposition(0)->setBaseWeeeTaxRowDisposition(0)->setWeeeTaxRowDisposition(0)->setBaseWeeeTaxAppliedAmount(0)->setBaseWeeeTaxAppliedRowAmount(0)->setWeeeTaxAppliedAmount(0)->setWeeeTaxAppliedRowAmount(0)->setProductOptions($options); $this->_subTotal += $rowTotal; return $orderItem; }
/** * Check product representation in item * * @param Mage_Catalog_Model_Product $product * @return bool */ public function representProduct($product) { $itemProduct = $this->getProduct(); if ($itemProduct->getId() != $product->getId()) { return false; } $itemOptions = $this->getOptions(); $productOptions = $product->getCustomOptions(); foreach ($itemOptions as $option) { $code = $option->getCode(); if (in_array($code, $this->_notRepresentOptions)) { continue; } if (!isset($productOptions[$code]) || $productOptions[$code]->getValue() === null || $productOptions[$code]->getValue() != $option->getValue()) { return false; } } return true; }
/** * Check product representation in item * * @param Mage_Catalog_Model_Product $product * @return bool */ public function isRepresentProduct($product) { if ($this->getProductId() != $product->getId()) { return false; } $productCustomOptions = $product->getCustomOptions(); if (empty($productCustomOptions['info_buyRequest'])) { return false; } $requestOption = $productCustomOptions['info_buyRequest']; $requestArray = unserialize($requestOption->getValue()); $selfOptions = unserialize($this->getCustomOptions()); if (!$this->_compareOptions($requestArray, $selfOptions)) { return false; } if (!$this->_compareOptions($selfOptions, $requestArray)) { return false; } return true; }
/** * add product in order * * @access protected * @param $product, $qty, $price * @return order object * */ function _productToOrderItem(Mage_Catalog_Model_Product $product, $qty = 1, $price) { if ($price) { $finalPrice = $price; } else { $finalPrice = $product->getFinalPrice(); } $rowTotal = $finalPrice * $qty; $options = $product->getCustomOptions(); $optionsByCode = array(); foreach ($options as $option) { $quoteOption = Mage::getModel('sales/quote_item_option')->setData($option->getData())->setProduct($option->getProduct()); $optionsByCode[$quoteOption->getCode()] = $quoteOption; } $product->setCustomOptions($optionsByCode); // DECREMENTE O STOCK $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId()); if ($stockItem->getManageStock()) { $stockItem->setData('qty', $stockItem->getQty() - $product['qty']); } $stockItem->save(); $options = $product->getTypeInstance(true)->getOrderOptions($product); $orderItem = Mage::getModel('sales/order_item')->setStoreId($this->_storeId)->setQuoteItemId(0)->setQuoteParentItemId(NULL)->setProductId($product->getId())->setProductType($product->getTypeId())->setQtyBackordered(NULL)->setTotalQtyOrdered($product['rqty'])->setQtyOrdered($product['qty'])->setName($product->getName())->setSku($product->getSku())->setPrice($finalPrice)->setBasePrice($finalPrice)->setOriginalPrice($finalPrice)->setRowTotal($rowTotal)->setBaseRowTotal($rowTotal)->setWeeeTaxApplied(serialize(array()))->setBaseWeeeTaxDisposition(0)->setWeeeTaxDisposition(0)->setBaseWeeeTaxRowDisposition(0)->setWeeeTaxRowDisposition(0)->setBaseWeeeTaxAppliedAmount(0)->setBaseWeeeTaxAppliedRowAmount(0)->setWeeeTaxAppliedAmount(0)->setWeeeTaxAppliedRowAmount(0)->setProductOptions($options); $this->_subTotal += $rowTotal; return $orderItem; }