/**
  * Get one line item key-value array
  *
  * @param Mage_Core_Model_Abstract $salesEntity
  * @param Varien_Object $item
  * @return array
  */
 protected function _prepareLineItemFields(Mage_Core_Model_Abstract $salesEntity, Varien_Object $item)
 {
     if ($salesEntity instanceof Mage_Sales_Model_Order) {
         $qty = $item->getQtyOrdered();
         $amount = $item->getBasePrice();
         // TODO: nominal item for order
     } else {
         $qty = $item->getTotalQty();
         $amount = $item->isNominal() ? 0 : $item->getBaseCalculationPrice();
     }
     // workaround in case if item subtotal precision is not compatible with PayPal (.2)
     $subAggregatedLabel = '';
     if ((double) $amount - round((double) $amount, 2)) {
         $amount = $amount * $qty;
         $subAggregatedLabel = ' x' . $qty;
         $qty = 1;
     }
     return array('id' => $item->getSku(), 'name' => $item->getName() . $subAggregatedLabel, 'qty' => $qty, 'amount' => (double) $amount);
 }
Example #2
0
 /**
  * Add a usual line item with amount and qty
  *
  * @param Varien_Object $salesItem
  * @return Varien_Object
  */
 protected function _addRegularItem(Varien_Object $salesItem)
 {
     if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
         $qty = (int) $salesItem->getQtyOrdered();
         $amount = (double) $salesItem->getBasePrice();
         // TODO: nominal item for order
     } else {
         $qty = (int) $salesItem->getTotalQty();
         $amount = $salesItem->isNominal() ? 0 : (double) $salesItem->getBaseCalculationPrice();
     }
     // workaround in case if item subtotal precision is not compatible with PayPal (.2)
     $subAggregatedLabel = '';
     if ($amount - round($amount, 2)) {
         $amount = $amount * $qty;
         $subAggregatedLabel = ' x' . $qty;
         $qty = 1;
     }
     // aggregate item price if item qty * price does not match row total
     if ($amount * $qty != $salesItem->getBaseRowTotal()) {
         $amount = (double) $salesItem->getBaseRowTotal();
         $subAggregatedLabel = ' x' . $qty;
         $qty = 1;
     }
     return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku());
 }