/** * Copy product collection surcharges from another collection to this one (e.g. Cart to Order) * @param IsotopeProductCollection * @return array */ public function copySurchargesFrom(IsotopeProductCollection $objSource, array $arrItemMap = array()) { $this->ensureNotLocked(); $arrIds = array(); $time = time(); $sorting = 128; foreach ($objSource->getSurcharges() as $objSourceSurcharge) { $objSurcharge = clone $objSourceSurcharge; $objSurcharge->pid = $this->id; $objSurcharge->tstamp = $time; $objSurcharge->sorting = $sorting; // Convert surcharge amount for individual product IDs $objSurcharge->convertCollectionItemIds($arrItemMap); $objSurcharge->save(); $arrIds[$sorting] = $objSurcharge->id; $sorting += 128; } // Empty cache $this->arrSurcharges = null; $this->arrCache = null; return $arrIds; }
/** * Return the PayPal form. * * @param IsotopeProductCollection|Order $objOrder The order being places * @param \Module|Checkout $objModule The checkout module instance * * @return string */ public function checkoutForm(IsotopeProductCollection $objOrder, \Module $objModule) { $arrData = array(); $fltDiscount = 0; $i = 0; foreach ($objOrder->getItems() as $objItem) { // Set the active product for insert tags replacement if ($objItem->hasProduct()) { Product::setActive($objItem->getProduct()); } $strConfig = ''; $arrConfig = $objItem->getConfiguration(); if (!empty($arrConfig)) { array_walk($arrConfig, function (&$option) { $option = $option['label'] . ': ' . (string) $option; }); $strConfig = ' (' . implode(', ', $arrConfig) . ')'; } $arrData['item_number_' . ++$i] = $objItem->getSku(); $arrData['item_name_' . $i] = \StringUtil::restoreBasicEntities($objItem->getName() . $strConfig); $arrData['amount_' . $i] = $objItem->getPrice(); $arrData['quantity_' . $i] = $objItem->quantity; } foreach ($objOrder->getSurcharges() as $objSurcharge) { if (!$objSurcharge->addToTotal) { continue; } // PayPal does only support one single discount item if ($objSurcharge->total_price < 0) { $fltDiscount -= $objSurcharge->total_price; continue; } $arrData['item_name_' . ++$i] = $objSurcharge->label; $arrData['amount_' . $i] = $objSurcharge->total_price; } $objTemplate = new \Isotope\Template('iso_payment_paypal'); $objTemplate->setData($this->arrData); $objTemplate->id = $this->id; $objTemplate->action = 'https://www.' . ($this->debug ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr'; $objTemplate->invoice = $objOrder->id; $objTemplate->data = array_map('specialchars', $arrData); $objTemplate->discount = $fltDiscount; $objTemplate->address = $objOrder->getBillingAddress(); $objTemplate->currency = $objOrder->currency; $objTemplate->return = \Environment::get('base') . $objModule->generateUrlForStep('complete', $objOrder); $objTemplate->cancel_return = \Environment::get('base') . $objModule->generateUrlForStep('failed'); $objTemplate->notify_url = \Environment::get('base') . 'system/modules/isotope/postsale.php?mod=pay&id=' . $this->id; $objTemplate->headline = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][0]); $objTemplate->message = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][1]); $objTemplate->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][2]); $objTemplate->noscript = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][3]); return $objTemplate->parse(); }
private function getCollectionTotalAsXML(IsotopeProductCollection $objCollection) { $intRebate = 0; $intRebateGross = 0; $strShippingName = ''; $intShippingPrice = 0; $intShippingPriceGross = 0; foreach ($objCollection->getSurcharges() as $objSurcharge) { if ($objSurcharge->total_price < 0) { $intRebate += round($objSurcharge->tax_free_total_price * 100); $intRebateGross += round($objSurcharge->total_price * 100); } elseif ($objSurcharge instanceof Shipping) { $strShippingName = $objSurcharge->label; $intShippingPrice += round($objSurcharge->tax_free_total_price * 100); $intShippingPriceGross += round($objSurcharge->total_price * 100); } } $xml = new \DOMDocument(); $total = $xml->createElement('total'); if ($intShippingPrice != 0 || $intShippingPriceGross != 0) { $shippingName = $xml->createAttribute('shippingname'); $shippingName->value = $strShippingName; $total->appendChild($shippingName); $shippingPrice = $xml->createAttribute('shippingprice'); $shippingPrice->value = $intShippingPrice; $total->appendChild($shippingPrice); $shippingPriceGross = $xml->createAttribute('shippingpricegross'); $shippingPriceGross->value = $intShippingPriceGross; $total->appendChild($shippingPriceGross); } if ($intRebate != 0 || $intRebateGross != 0) { $rebate = $xml->createAttribute('rebate'); $rebate->value = $intRebate; $total->appendChild($rebate); $rebateGross = $xml->createAttribute('rebategross'); $rebateGross->value = $intRebateGross; $total->appendChild($rebateGross); } $cartTotalPrice = $xml->createAttribute('carttotalprice'); $cartTotalPrice->value = round($objCollection->getTaxFreeTotal() * 100); $total->appendChild($cartTotalPrice); $cartTotalPriceGross = $xml->createAttribute('carttotalpricegross'); $cartTotalPriceGross->value = round($objCollection->getTotal() * 100); $total->appendChild($cartTotalPriceGross); $currency = $xml->createAttribute('currency'); $currency->value = $objCollection->currency; $total->appendChild($currency); $xml->appendChild($total); return $xml->saveXML($xml->documentElement); }