/** * Generates payment drop down list for this shop * * @param array $basketArray Array of template marker * * @return array Template marker */ public function makePayment(array $basketArray = array()) { $this->paymentProduct = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Product', $this->conf['payProdId'], $this->getFrontendController()->tmpl->setup['config.']['sys_language_uid']); $this->paymentProduct->loadData(); $this->paymentProduct->loadArticles(); $this->basketPaymentArticles = $this->basket->getArticlesByArticleTypeUidAsUidlist(PAYMENTARTICLETYPE); $select = '<select name="' . $this->prefixId . '[payArt]" onChange="this.form.submit();">'; $addPleaseSelect = FALSE; $addDefaultPaymentToBasket = FALSE; // Check if a Payment is selected if not, add standard payment if (count($this->basketPaymentArticles) == 0) { // Check if Payment selection is forced if ($this->conf['payment.']['forceSelection']) { // Add Please Select Option $select .= '<option value="-1" selected="selected">' . $this->pi_getLL('lang_payment_force') . '</option>'; $addPleaseSelect = TRUE; } else { // No payment article is in the basket, so add the first one $addDefaultPaymentToBasket = TRUE; } } $allowedArticles = array(); if ($this->conf['payment.']['allowedArticles']) { $allowedArticles = explode(',', $this->conf['payment.']['allowedArticles']); } // Check if payment articles are allowed $newAllowedArticles = array(); /** * Article * * @var Tx_Commerce_Domain_Model_Article $article */ foreach ($this->paymentProduct->getArticleObjects() as $articleUid => $article) { if (!count($allowedArticles) || in_array($articleUid, $allowedArticles)) { $article->loadData(); $payment = $this->getPaymentObject($article->getClassname()); if ($payment->isAllowed()) { $newAllowedArticles[] = $articleUid; } } } // If default Paymentarticle is, for example, credit card // but when we have an article in the basket with the only possible // payment method like debit, this ensures that there is still the correct // payment article in the basket. // @todo: Refactor default handling if (count($newAllowedArticles) == 1 && $this->conf['defaultPaymentArticleId'] != $newAllowedArticles[0]) { $this->conf['defaultPaymentArticleId'] = $newAllowedArticles[0]; } $allowedArticles = $newAllowedArticles; unset($newAllowedArticles); // Hook to allow to define/overwrite individually, which payment // articles are allowed if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['paymentArticles'])) { GeneralUtility::deprecationLog(' hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi2/class.tx_commerce_pi2.php\'][\'paymentArticles\'] is deprecated since commerce 1.0.0, it will be removed in commerce 1.4.0, please use instead $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Controller/BasketController.php\'][\'paymentArticles\'] '); foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['paymentArticles'] as $classRef) { $hookObj =& GeneralUtility::getUserObj($classRef); if (method_exists($hookObj, 'paymentAllowedArticles')) { $allowedArticles = $hookObj->paymentAllowedArticles($this, $allowedArticles); } } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['paymentArticles'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['paymentArticles'] as $classRef) { $hookObj =& GeneralUtility::getUserObj($classRef); if (method_exists($hookObj, 'paymentAllowedArticles')) { $allowedArticles = $hookObj->paymentAllowedArticles($this, $allowedArticles); } } } $first = FALSE; $priceNet = ''; $priceGross = ''; /** * Article * * @var $article Tx_Commerce_Domain_Model_Article */ foreach ($this->paymentProduct->getArticleObjects() as $articleUid => $article) { if (!count($allowedArticles) || in_array($articleUid, $allowedArticles)) { $select .= '<option value="' . $articleUid . '"'; if ($articleUid == $this->basketPaymentArticles[0] || $addDefaultPaymentToBasket && $articleUid == $this->conf['defaultPaymentArticleId'] && !$addPleaseSelect) { $addDefaultPaymentToBasket = FALSE; $first = TRUE; $select .= ' selected="selected"'; $this->basket->addArticle($articleUid); $priceNet = Tx_Commerce_ViewHelpers_Money::format($article->getPriceNet(), $this->currency); $priceGross = Tx_Commerce_ViewHelpers_Money::format($article->getPriceGross(), $this->currency); } elseif (!$first) { $priceNet = Tx_Commerce_ViewHelpers_Money::format($article->getPriceNet(), $this->currency); $priceGross = Tx_Commerce_ViewHelpers_Money::format($article->getPriceGross(), $this->currency); $this->basket->deleteArticle($articleUid); } $select .= '>' . $article->getTitle() . '</option>'; } } $select .= '</select>'; // Set Prices to 0, if "please select " is shown if ($addPleaseSelect) { $priceGross = Tx_Commerce_ViewHelpers_Money::format(0, $this->currency); $priceNet = Tx_Commerce_ViewHelpers_Money::format(0, $this->currency); } $basketArray['###PAYMENT_SELECT_BOX###'] = $select; $basketArray['###PAYMENT_PRICE_GROSS###'] = $priceGross; $basketArray['###PAYMENT_PRICE_NET###'] = $priceNet; $this->basket->storeData(); return $basketArray; }