/** * append items, shipping and discount to the payment object * * @param Mage_Sales_Model_Order_Item $order * @param SofortLib_Multipay $sofortPayment */ private function _appendItems($order, $sofortPayment) { //items $discountTax = 19; foreach ($order->getAllVisibleItems() as $item) { if (($item->product_type == 'downloadable' || $item->product_type == 'virtual') && $item->getRowTotal() > 0) { throw new Exception(Mage::helper('pnsofortueberweisung')->__('Kauf auf Rechnung not allowed for downloadable or virtual products')); } $name = $item->getName(); $uid = $item->getSku() . "-" . $item->getItemId(); // FIXME getDescription is not default method for Mage_Sales_Model_Order_Item ? $desc = $item->getDescription(); // configurable product if ($item->product_type == 'configurable') { $productOptions = unserialize($item->product_options); // check attributes if (!empty($productOptions['attributes_info'])) { $configAttr = array(); foreach ($productOptions['attributes_info'] as $pOp) { $configAttr[] = $pOp['value']; } if (!empty($configAttr)) { $desc = implode(", ", $configAttr) . "\n" . $desc; } } } else { if ($item->product_type == 'bundle') { $productOptions = unserialize($item->product_options); // check bundle options if (!empty($productOptions['bundle_options'])) { $bundleTitle = array(); foreach ($productOptions['bundle_options'] as $pOp) { if (!empty($pOp['value'])) { foreach ($pOp['value'] as $bValue) { $bundleTitle[] = $bValue['title']; } } } if (!empty($bundleTitle)) { $desc = implode(", ", $bundleTitle) . "\n" . $desc; } } } } // add item $sofortPayment->addSofortrechnungItem(md5($uid), $item->getSku(), $name, $this->_getPriceInclTax($item), 0, $desc, $item->getQtyOrdered() - $item->getQtyCanceled() - $item->getQtyRefunded(), $item->getTaxPercent()); if ($item->getTaxPercent() > 0) { // tax of discount is min of cart-items $discountTax = min($item->getTaxPercent(), $discountTax); } } //shipping if ($order->getShippingAmount() != 0) { $shippingTax = round($order->getShippingTaxAmount() / $order->getShippingAmount() * 100); } else { $shippingTax = 0; } // check if amount is removed if ($order->getShippingAmount() - $order->getShippingRefunded() > 0) { $sofortPayment->addSofortrechnungItem(1, 1, $order->getShippingDescription(), $this->_getShippingInclTax($order), 1, '', 1, $shippingTax); } //discount if ($order->getDiscountAmount() != 0) { $sofortPayment->addSofortrechnungItem(2, 2, Mage::helper('sales')->__('Discount'), $order->getDiscountAmount(), 2, '', 1, $discountTax); } }