/**
  * add giftwrap/giftcard pricing to the payload
  * @param  IGifting
  * @param  Varien_Object
  * @return self
  */
 protected function _addGiftWrapPricing(IGifting $giftingPayload, Varien_Object $giftingItem)
 {
     $gwPrice = $giftingItem->getGwPrice();
     $gwCardPrice = $giftingItem->getGwCardPrice();
     if ($gwPrice || $gwCardPrice) {
         $amount = $this->_helper->calculateGwItemRowTotal($giftingItem);
         $pg = $this->_getPriceGroup($giftingPayload);
         $pg->setAmount($amount)->setUnitPrice($gwPrice + $gwCardPrice);
     }
     return $this;
 }
 /**
  * Trasfer data from an "item" with gifting options to a Gifting payload.
  * The "item" may be a quote item or quote address, as either may have
  * gift options data, retrievable in the same way.
  *
  * @param Varien_Object
  * @param IGfiting
  * @return IGifting
  */
 public function giftingItemToGiftingPayload(Varien_Object $giftItem, IGifting $giftingPayload)
 {
     $giftPricing = $giftingPayload->getEmptyGiftPriceGroup();
     $giftWrap = Mage::getModel('enterprise_giftwrapping/wrapping')->load($giftItem->getGwId());
     if ($giftWrap->getId()) {
         // For quote items (which will have a quantity), gift wrapping price
         // on the item will be the price for a single item to be wrapped,
         // total will be for cost for all items to be wrapped (qty * amount).
         // For addresses (which will have no quantity), gift wrapping price
         // on the address will be the price for wrapping all items for that
         // address, so total is just amount (1 * amount).
         $giftQty = $giftItem->getQty() ?: 1;
         // Add pricing data for gift wrapping - does not include discounts
         // as Magento does not support applying discounts to gift wrapping
         // out-of-the-box.
         $giftPricing->setUnitPrice($giftWrap->getBasePrice())->setAmount($giftItem->getGwPrice() * $giftQty)->setTaxClass($giftWrap->getEb2cTaxClass());
         $giftingPayload->setGiftItemId($giftWrap->getEb2cSku())->setGiftDescription($giftWrap->getDesign())->setGiftPricing($giftPricing);
     }
     return $giftingPayload;
 }
Example #3
0
 /**
  * Return totals of data object
  *
  * @param  Varien_Object $dataObject
  * @return array
  */
 public function getTotals($dataObject)
 {
     $totals = array();
     $displayWrappingBothPrices = false;
     $displayWrappingIncludeTaxPrice = false;
     $displayCardBothPrices = false;
     $displayCardIncludeTaxPrice = false;
     if ($dataObject instanceof Mage_Sales_Model_Order || $dataObject instanceof Mage_Sales_Model_Order_Invoice || $dataObject instanceof Mage_Sales_Model_Order_Creditmemo) {
         $displayWrappingBothPrices = $this->displaySalesWrappingBothPrices();
         $displayWrappingIncludeTaxPrice = $this->displaySalesWrappingIncludeTaxPrice();
         $displayCardBothPrices = $this->displaySalesCardBothPrices();
         $displayCardIncludeTaxPrice = $this->displaySalesCardIncludeTaxPrice();
     } elseif ($dataObject instanceof Mage_Sales_Model_Quote_Address_Total) {
         $displayWrappingBothPrices = $this->displayCartWrappingBothPrices();
         $displayWrappingIncludeTaxPrice = $this->displayCartWrappingIncludeTaxPrice();
         $displayCardBothPrices = $this->displayCartCardBothPrices();
         $displayCardIncludeTaxPrice = $this->displayCartCardIncludeTaxPrice();
     }
     /**
      * Gift wrapping for order totals
      */
     if ($displayWrappingBothPrices || $displayWrappingIncludeTaxPrice) {
         if ($displayWrappingBothPrices) {
             $this->_addTotalToTotals($totals, 'gw_order_excl', $dataObject->getGwPrice(), $dataObject->getGwBasePrice(), $this->__('Gift Wrapping for Order (Excl. Tax)'));
         }
         $this->_addTotalToTotals($totals, 'gw_order_incl', $dataObject->getGwPrice() + $dataObject->getGwTaxAmount(), $dataObject->getGwBasePrice() + $dataObject->getGwBaseTaxAmount(), $this->__('Gift Wrapping for Order (Incl. Tax)'));
     } else {
         $this->_addTotalToTotals($totals, 'gw_order', $dataObject->getGwPrice(), $dataObject->getGwBasePrice(), $this->__('Gift Wrapping for Order'));
     }
     /**
      * Gift wrapping for items totals
      */
     if ($displayWrappingBothPrices || $displayWrappingIncludeTaxPrice) {
         $this->_addTotalToTotals($totals, 'gw_items_incl', $dataObject->getGwItemsPrice() + $dataObject->getGwItemsTaxAmount(), $dataObject->getGwItemsBasePrice() + $dataObject->getGwItemsBaseTaxAmount(), $this->__('Gift Wrapping for Items (Incl. Tax)'));
         if ($displayWrappingBothPrices) {
             $this->_addTotalToTotals($totals, 'gw_items_excl', $dataObject->getGwItemsPrice(), $dataObject->getGwItemsBasePrice(), $this->__('Gift Wrapping for Items (Excl. Tax)'));
         }
     } else {
         $this->_addTotalToTotals($totals, 'gw_items', $dataObject->getGwItemsPrice(), $dataObject->getGwItemsBasePrice(), $this->__('Gift Wrapping for Items'));
     }
     /**
      * Printed card totals
      */
     if ($displayCardBothPrices || $displayCardIncludeTaxPrice) {
         $this->_addTotalToTotals($totals, 'gw_printed_card_incl', $dataObject->getGwCardPrice() + $dataObject->getGwCardTaxAmount(), $dataObject->getGwCardBasePrice() + $dataObject->getGwCardBaseTaxAmount(), $this->__('Printed Card (Incl. Tax)'));
         if ($displayCardBothPrices) {
             $this->_addTotalToTotals($totals, 'gw_printed_card_excl', $dataObject->getGwCardPrice(), $dataObject->getGwCardBasePrice(), $this->__('Printed Card (Excl. Tax)'));
         }
     } else {
         $this->_addTotalToTotals($totals, 'gw_printed_card', $dataObject->getGwCardPrice(), $dataObject->getGwCardBasePrice(), $this->__('Printed Card'));
     }
     return $totals;
 }
 /**
  * Calculating the order item gift wrapping row total when the passed in object is
  * a concrete 'sales/order_item' instance otherwise simply return the gift wrap price.
  * @param  Varien_Object $item
  * @return float
  */
 public function calculateGwItemRowTotal(Varien_Object $item)
 {
     $qty = $item instanceof Mage_Sales_Model_Order_Item ? $item->getQtyOrdered() : 1;
     return Mage::app()->getStore()->roundPrice($qty * $item->getGwPrice() + $item->getGwCardPrice());
 }