Exemplo n.º 1
0
 public static function crateFromOrderItem(Mage_Sales_Model_Order_Item $orderItem)
 {
     $productId = $orderItem->getProductId();
     /** @var Mage_Catalog_Model_Product $product */
     $product = Mage::getModel('catalog/product')->load($productId);
     $discounts = $product->getPrice() - $product->getFinalPrice();
     $aArticle = new self();
     $aArticle->id = $productId;
     $aArticle->name = $orderItem->getName();
     $aArticle->url = $product->getProductUrl();
     $aArticle->image_url = $product->getImageUrl();
     $aArticle->quantity = intval($orderItem->getQtyOrdered());
     $aArticle->price = Aplazame_Sdk_Serializer_Decimal::fromFloat($orderItem->getPrice() + $discounts);
     $aArticle->description = substr($product->getDescription(), 0, 255);
     $aArticle->tax_rate = Aplazame_Sdk_Serializer_Decimal::fromFloat(self::getProductTaxRate($product));
     $aArticle->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat($discounts);
     return $aArticle;
 }
 /**
  * Add Weee taxes child to the XML. Api version 23
  *
  * @param Mage_Core_Block_Template $renderer Product renderer
  * @param Mage_Sales_Model_Order_Item $item
  * @param Mage_XmlConnect_Model_Simplexml_Element $parentXml
  * @param array $params Params for Weee taxes: 'include' - Price including tax, 'is_subtotal' - Flag of subtotal
  * @param string $idPrefix
  * @param bool $isIncludeTax
  * @return null
  */
 public function addWeeeTaxesToPriceXmlApi23(Mage_Core_Block_Template $renderer, Mage_Sales_Model_Order_Item $item, Mage_XmlConnect_Model_Simplexml_Element $parentXml, $params = array(), $idPrefix, $isIncludeTax)
 {
     $weeTaxes = $renderer->getWeeeTaxes();
     if (empty($weeTaxes)) {
         return;
     }
     $typesOfDisplay = $renderer->getTypesOfDisplay();
     $row = isset($params['is_subtotal']) && $params['is_subtotal'] ? 'row_' : '';
     if ($isIncludeTax) {
         $weeeXml = $parentXml->addCustomChild('price', null, array('id' => 'weee'));
         /** @var $weeeXml Mage_XmlConnect_Model_Simplexml_Element */
         if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_1]) {
             foreach ($weeTaxes as $tax) {
                 $taxAmount = Mage::helper('xmlconnect')->formatPriceForXml($tax[$row . 'amount']);
                 $weeeXml->addCustomChild('item', $taxAmount, array('label' => $tax['title'], 'formatted_price' => $this->formatPrice($renderer, $tax[$row . 'amount'])));
             }
         } elseif ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_2] || $typesOfDisplay[self::PRICE_DISPLAY_TYPE_4]) {
             foreach ($weeTaxes as $tax) {
                 $taxAmount = Mage::helper('xmlconnect')->formatPriceForXml($tax[$row . 'amount_incl_tax']);
                 $weeeXml->addCustomChild('item', $taxAmount, array('label' => $tax['title'], 'formatted_price' => $this->formatPrice($renderer, $tax[$row . 'amount_incl_tax'])));
             }
         }
     }
     if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_2]) {
         if (!empty($params['include'])) {
             // including tax
             if (isset($params['is_subtotal'])) {
                 $total = $params['include'] + $item->getWeeeTaxAppliedRowAmount();
             } else {
                 $total = $params['include'] + $renderer->getWeeeTaxAppliedAmount();
             }
         } else {
             // excluding tax
             if (isset($params['is_subtotal'])) {
                 $total = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount() + $item->getWeeeTaxRowDisposition();
             } else {
                 $total = $item->getPrice() + $renderer->getWeeeTaxAppliedAmount() + $renderer->getWeeeTaxDisposition();
             }
         }
         $totalNodeId = $idPrefix . 'fpt_total_' . ($isIncludeTax ? self::INCLUDING_TAX_ID : self::EXCLUDING_TAX_ID);
         $parentXml->addCustomChild('price', Mage::helper('xmlconnect')->formatPriceForXml($total), array('id' => $totalNodeId, 'label' => $isIncludeTax ? $renderer->helper('weee')->__('Total incl. tax') : $renderer->helper('weee')->__('Total excl. tax'), 'formatted_price' => $this->formatPrice($renderer, $total)));
     }
 }
Exemplo n.º 3
0
 /**
  * Add Weee taxes child to the XML
  *
  * @param Mage_Core_Block_Template $renderer Product renderer
  * @param Mage_Sales_Model_Order_Item $item
  * @param Mage_XmlConnect_Model_Simplexml_Element $parentXml
  * @param array $params Params for Weee taxes: 'include' - Price including tax, 'is_subtotal' - Flag of subtotal
  * @return null
  */
 public function addWeeeTaxesToPriceXml(Mage_Core_Block_Template $renderer, Mage_Sales_Model_Order_Item $item, Mage_XmlConnect_Model_Simplexml_Element $parentXml, $params = array())
 {
     $weeTaxes = $renderer->getWeeeTaxes();
     if (empty($weeTaxes)) {
         return;
     }
     $typesOfDisplay = $renderer->getTypesOfDisplay();
     $row = isset($params['is_subtotal']) && $params['is_subtotal'] ? 'row_' : '';
     /** @var $weeeXml Mage_XmlConnect_Model_Simplexml_Element */
     if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_1]) {
         $weeeXml = $parentXml->addChild('weee');
         foreach ($weeTaxes as $tax) {
             $weeeXml->addCustomChild('tax', $this->formatPrice($renderer, $tax[$row . 'amount']), array('label' => $tax['title']));
         }
     } elseif ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_2] || $typesOfDisplay[self::PRICE_DISPLAY_TYPE_4]) {
         $weeeXml = $parentXml->addChild('weee');
         foreach ($weeTaxes as $tax) {
             $weeeXml->addCustomChild('tax', $this->formatPrice($renderer, $tax[$row . 'amount_incl_tax']), array('label' => $tax['title']));
         }
     }
     if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_2]) {
         if (!is_null($params['include'])) {
             // including tax
             if (isset($params['is_subtotal'])) {
                 $total = $params['include'] + $item->getWeeeTaxAppliedRowAmount();
             } else {
                 $total = $params['include'] + $renderer->getWeeeTaxAppliedAmount();
             }
         } else {
             // excluding tax
             if ($params['is_subtotal']) {
                 $total = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount() + $item->getWeeeTaxRowDisposition();
             } else {
                 $total = $item->getPrice() + $renderer->getWeeeTaxAppliedAmount() + $renderer->getWeeeTaxDisposition();
             }
         }
         if (!isset($weeeXml)) {
             $weeeXml = $parentXml->addChild('weee');
         }
         $weeeXml->addCustomChild('total', $this->formatPrice($renderer, $total), array('label' => $renderer->helper('weee')->__('Total')));
     }
 }
Exemplo n.º 4
0
 protected function _writeOrderItem(Mage_Sales_Model_Order_Item $item, XMLWriter $xml, $storeId = null)
 {
     // inherit some attributes from parent order item
     if ($item->getParentItemId() && !$item->getParentItem()) {
         $item->setParentItem(Mage::getModel('sales/order_item')->load($item->getParentItemId()));
     }
     // only inherit if parent has been hidden
     if ($item->getParentItem() && $item->getPrice() == 0.0 && Mage::helper('auctaneapi')->isExcludedProductType($item->getParentItem()->getProductType())) {
         $item->setPrice($item->getParentItem()->getPrice());
     }
     /* @var $gift Mage_GiftMessage_Model_Message */
     $gift = Mage::helper('giftmessage/message')->getGiftMessage(!$item->getGiftMessageId() && $item->getParentItem() ? $item->getParentItem()->getGiftMessageId() : $item->getGiftMessageId());
     $item->setGift($gift->isObjectNew() ? 'false' : 'true');
     if (!$gift->isObjectNew()) {
         $item->setGiftMessage(sprintf("From: %s\nTo: %s\nMessage: %s", $gift->getSender(), $gift->getRecipient(), $gift->getMessage()));
     }
     /* @var $product Mage_Catalog_Model_Product */
     $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($item->getProductId());
     // inherit some attributes from parent product item
     if ($parentProduct = $this->_getOrderItemParentProduct($item, $storeId)) {
         if (!$product->getImage() || $product->getImage() == 'no_selection') {
             $product->setImage($parentProduct->getImage());
         }
         if (!$product->getSmallImage() || $product->getSmallImage() == 'no_selection') {
             $product->setSmallImage($parentProduct->getSmallImage());
         }
         if (!$product->getThumbnail() || $product->getThumbnail() == 'no_selection') {
             $product->setThumbnail($parentProduct->getThumbnail());
         }
     }
     $xml->startElement('Item');
     $helper = Mage::helper('auctaneapi');
     if (Mage::helper('auctaneapi')->getExportPriceType($item->getOrder()->getStoreId()) == Auctane_Api_Model_System_Source_Config_Prices::BASE_PRICE) {
         $helper->fieldsetToXml('base_sales_order_item', $item, $xml);
     } else {
         $helper->fieldsetToXml('sales_order_item', $item, $xml);
     }
     /* using emulation so that product images come from the correct store */
     $appEmulation = Mage::getSingleton('core/app_emulation');
     $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($product->getStoreId());
     Mage::helper('auctaneapi')->fieldsetToXml('sales_order_item_product', $product, $xml);
     $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
     $xml->startElement('Options');
     $this->_writeOrderProductAttribute($product, $xml, $storeId);
     // items may have several custom options chosen by customer
     foreach ((array) $item->getProductOptionByCode('options') as $option) {
         $this->_writeOrderItemOption($option, $xml, $storeId);
     }
     $buyRequest = $item->getProductOptionByCode('info_buyRequest');
     if ($buyRequest && @$buyRequest['super_attribute']) {
         // super_attribute is non-null and non-empty, there must be a Configurable involved
         $parentItem = $this->_getOrderItemParent($item);
         /* export configurable custom options as they are stored in parent */
         foreach ((array) $parentItem->getProductOptionByCode('options') as $option) {
             $this->_writeOrderItemOption($option, $xml, $storeId);
         }
         foreach ((array) $parentItem->getProductOptionByCode('attributes_info') as $option) {
             $this->_writeOrderItemOption($option, $xml, $storeId);
         }
     }
     $xml->endElement();
     // Options
     $xml->endElement();
     // Item
 }
Exemplo n.º 5
0
 /**
  * Initialize creation data from existing order Item
  *
  * @param Mage_Sales_Model_Order_Item $orderItem
  * @param int $qty
  * @return Mage_Sales_Model_Quote_Item | string
  */
 public function initFromOrderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = null)
 {
     if (!$orderItem->getId()) {
         return $this;
     }
     $product = Mage::getModel('catalog/product')->setStoreId($this->getSession()->getStoreId())->load($orderItem->getProductId());
     if ($product->getId()) {
         $product->setSkipCheckRequiredOption(true);
         $buyRequest = $orderItem->getBuyRequest();
         if (is_numeric($qty)) {
             $buyRequest->setQty($qty);
         }
         $item = $this->getQuote()->addProduct($product, $buyRequest);
         if (is_string($item)) {
             return $item;
         }
         if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {
             $item->addOption(new Varien_Object(array('product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions))));
         }
         if ($product->getPrice() != $orderItem->getPrice()) {
             $item->setCustomPrice($orderItem->getPrice());
             $item->setOriginalCustomPrice($orderItem->getPrice());
         }
         Mage::dispatchEvent('buyback_convert_order_item_to_quote_item', array('order_item' => $orderItem, 'quote_item' => $item));
         return $item;
     }
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Retrieve
  *
  * @param Mage_Sales_Model_Order_Item $item
  * @return unknown
  */
 public function itemToQuoteItem(Mage_Sales_Model_Order_Item $item)
 {
     $quoteItem = Mage::getModel('sales/quote_item')->setStoreId($item->getStoreId())->setQuoteItemId($item->getId())->setProductId($item->getProductId())->setSuperProductId($item->getSuperProductId())->setParentProductId($item->getParentProductId())->setSku($item->getSku())->setName($item->getName())->setDescription($item->getDescription())->setWeight($item->getWeight())->setCustomPrice($item->getPrice())->setDiscountPercent($item->getDiscountPercent())->setDiscountAmount($item->getDiscountAmount())->setTaxPercent($item->getTaxPercent())->setTaxAmount($item->getTaxAmount())->setRowWeight($item->getRowWeight())->setRowTotal($item->getRowTotal())->setAppliedRuleIds($item->getAppliedRuleIds())->setBaseDiscountAmount($item->getBaseDiscountAmount())->setBaseTaxAmount($item->getBaseTaxAmount())->setBaseRowTotal($item->getBaseRowTotal());
     return $quoteItem;
 }
 /**
  * fillout the merchandise price group payload for the order item
  * @param  Mage_Sales_Model_Order_Item
  * @param  IPriceGroup
  * @return self
  */
 protected function prepareMerchandisePricing(Mage_Sales_Model_Order_Item $item, IPriceGroup $merch)
 {
     $merch->setAmount($item->getRowTotal())->setUnitPrice($item->getPrice());
     $this->discountHelper->transferDiscounts($item, $merch);
     return $this;
 }
Exemplo n.º 8
0
 /**
  * Initialize creation data from existing order Item
  *
  * @param Mage_Sales_Model_Order_Item $orderItem
  * @param int $qty
  * @return Mage_Sales_Model_Quote_Item | string
  */
 public function initFromOrderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = null)
 {
     if (!$orderItem->getId()) {
         return $this;
     }
     $product = Mage::getModel('catalog/product')->setStoreId($this->getSession()->getStoreId())->load($orderItem->getProductId());
     if ($product->getId()) {
         $product->setSkipCheckRequiredOption(true);
         $buyRequest = $orderItem->getBuyRequest();
         if (is_numeric($qty)) {
             $buyRequest->setQty($qty);
         }
         $item = $this->getQuote()->addProduct($product, $buyRequest);
         if (is_string($item)) {
             return $item;
         }
         /*********************************************Set custom price selected starts************************************************************/
         if (!$this->getSession()->getReordered() && $orderItem->getOriginalPrice() != $orderItem->getPrice()) {
             if ($orderItem->getProductType() == 'configurable' || $orderItem->getProductType() == 'bundle') {
                 $productId = $orderItem->getProductId();
                 $quoteItemId = $orderItem->getQuoteItemId();
                 $items = $this->getQuote()->getItemsCollection();
                 foreach ($items as $item) {
                     if ($item->getProduct()->getId() == $productId && !$item->getApplyPriceFlag()) {
                         if ($orderItem->getOriginalPrice() != $orderItem->getPrice()) {
                             $item->setCustomPrice($orderItem->getPrice())->setOriginalCustomPrice($orderItem->getPrice());
                         }
                         //$item->setApplyPriceFlag(true);
                     }
                 }
             } else {
                 $item->setCustomPrice($orderItem->getPrice())->setOriginalCustomPrice($orderItem->getPrice());
             }
         }
         /*********************************************Set custom price selected ends************************************************************/
         if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {
             $item->addOption(new Varien_Object(array('product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions))));
         }
         Mage::dispatchEvent('sales_convert_order_item_to_quote_item', array('order_item' => $orderItem, 'quote_item' => $item));
         return $item;
     }
     return $this;
 }
 /**
  * Set correct item prices ((original price / new qty) * old qty)
  *
  * @param Mage_Sales_Model_Order_Item $orderItem
  * @param int $oldQty
  * @param int $newQty
  * @return Mage_Sales_Model_Order_Item
  */
 protected function _correctPrices($orderItem, $oldQty, $newQty)
 {
     $orderItem->setPrice($orderItem->getPrice() / $newQty * $oldQty);
     $orderItem->setBasePrice($orderItem->getBasePrice() / $newQty * $oldQty);
     $orderItem->setOriginalPrice($orderItem->getOriginalPrice() / $newQty * $oldQty);
     $orderItem->setBaseOriginalPrice($orderItem->getBaseOriginalPrice() / $newQty * $oldQty);
     $orderItem->setPriceInclTax($orderItem->getPriceInclTax() / $newQty * $oldQty);
     $orderItem->setBasePriceInclTax($orderItem->getBasePriceInclTax() / $newQty * $oldQty);
     return $orderItem;
 }
Exemplo n.º 10
0
 /**
  * @param Mage_Sales_Model_Order_Item $orderItem
  *
  * @return string
  */
 public function getFrontendProductPrice(Mage_Sales_Model_Order_Item $orderItem)
 {
     $itemPrice = $orderItem->getPrice();
     if ($orderItem->getParentItemId()) {
         $parentItem = Mage::getModel('sales/order_item')->load($orderItem->getParentItemId());
         if ($parentItem->getProductType() != 'bundle') {
             $itemPrice = $parentItem->getPrice();
         }
     }
     return $orderItem->getOrder()->getOrderCurrency()->format($itemPrice);
 }