/** * This method is called in the last step. Here can be made some final checks * or whatever is needed to be done before saving some data in the database. * Write any errors into $this->errorMessages! * To save some additional data in the database use the method updateOrder(). * * @param array $config Configuration from TYPO3_CONF_VARS * @param array $session Current session data * @param Tx_Commerce_Domain_Model_Basket $basket Basket object * * @return bool Check if everything was ok */ public function finishingFunction(array $config = array(), array $session = array(), Tx_Commerce_Domain_Model_Basket $basket = NULL) { /** * Payment library * * @var Tx_Commerce_Payment_Payment $paymentLib */ $paymentLib = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Commerce_Payment_Payment'); // I think there is a new URL for testing with wirecard, so overwrite // the old value. you can replace this with your own. $paymentLib->setUrl('https://c3-test.wirecard.com'); $paymentLib->paymentmethod = 'creditcard'; $paymentLib->paymenttype = 'cc'; $paymentLib->setPaymentData(array('kk_number' => $session['payment']['cc_number'], 'exp_month' => $session['payment']['cc_expirationMonth'], 'exp_year' => $session['payment']['cc_expirationYear'], 'holder' => $session['payment']['cc_holder'], 'cvc' => $session['payment']['cc_checksum'])); $parent = $this->paymentObject->getParentObject(); $actCurrency = $parent->conf['currency'] != '' ? $parent->conf['currency'] : 'EUR'; $paymentLib->setTransactionData(array('amount' => $basket->getSumGross(), 'currency' => $actCurrency)); $paymentLib->sendData = $paymentLib->getwirecardXML(); $back = $paymentLib->sendTransaction(); if (!$back) { $this->errorMessages = array_merge($this->errorMessages, (array) $paymentLib->getError()); return FALSE; } else { $this->paymentRefId = $paymentLib->referenzID; // The ReferenceID should be stored here, so that it can be // added to the record in updateOrder() return TRUE; } }
/** * Renders the product list for the basket * * @return string HTML Content */ protected function makeProductList() { $content = ''; $hookObjectsArr = array(); if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['makeProductList'])) { GeneralUtility::deprecationLog(' hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi2/class.tx_commerce_pi2.php\'][\'makeProductList\'] 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\'][\'makeProductList\'] '); foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['makeProductList'] as $classRef) { $hookObjectsArr[] =& GeneralUtility::getUserObj($classRef); } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['makeProductList'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['makeProductList'] as $classRef) { $hookObjectsArr[] =& GeneralUtility::getUserObj($classRef); } } $hookObject = NULL; if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['alternativePrefixId']) { GeneralUtility::deprecationLog(' hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi2/class.tx_commerce_pi2.php\'][\'alternativePrefixId\'] 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\'][\'alternativePrefixId\'] '); $hookObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['alternativePrefixId']); } if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['alternativePrefixId']) { $hookObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['alternativePrefixId']); } if (method_exists($hookObject, 'SingeDisplayPrefixId')) { $altPrefixSingle = $hookObject->SingeDisplayPrefixId(); } else { $altPrefixSingle = $this->prefixId; } $list = array(); $articleTypes = GeneralUtility::trimExplode(',', $this->conf['regularArticleTypes'], TRUE); foreach ($articleTypes as $articleType) { $list = array_merge($list, $this->basket->getArticlesByArticleTypeUidAsUidlist($articleType)); } // ########### product list ###################### $templateMarker[] = '###' . strtoupper($this->conf['templateMarker.']['items_listview']) . '###'; $templateMarker[] = '###' . strtoupper($this->conf['templateMarker.']['items_listview2']) . '###'; $changerowcount = 0; foreach ($list as $basketItemId) { // Fill marker arrays with product/article values /** * Basket item * * @var $basketItem Tx_Commerce_Domain_Model_BasketItem */ $basketItem = $this->basket->getBasketItem($basketItemId); // Check stock $stockOk = TRUE; if ($this->conf['checkStock'] == 1) { if (!$basketItem->getArticle()->hasStock($basketItem->getQuantity())) { $stockOk = FALSE; } } // Check accessible $access = $basketItem->getProduct()->isAccessible() && $basketItem->getArticle()->isAccessible(); // Only if Stock is ok and Access is ok (could have been changed since // the article was put into the basket if ($stockOk && $access) { $safePrefix = $this->prefixId; $typoLinkConf = array(); $typoLinkConf['parameter'] = $this->conf['listPid']; $typoLinkConf['useCacheHash'] = 1; $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[catUid]=' . $basketItem->getProduct()->getMasterparentCategory(); $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[showUid]=' . $basketItem->getProduct()->getUid(); if ($this->basketHashValue) { $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[basketHashValue]=' . $this->basketHashValue; } // @todo change link building to pure TypoScript, cObj->data usage required $lokalTsProduct = $this->addTypoLinkToTypoScript($this->conf['fields.']['products.'], $typoLinkConf); $lokalTsArticle = $this->addTypoLinkToTypoScript($this->conf['fields.']['articles.'], $typoLinkConf); $this->prefixId = $altPrefixSingle; $wrapMarkerArray['###PRODUCT_LINK_DETAIL###'] = explode('|', $this->pi_list_linkSingle('|', $basketItem->getProduct()->getUid(), 1, array('catUid' => (int) $basketItem->getProduct()->getMasterparentCategory()), FALSE, $this->conf['listPid'])); $this->prefixId = $safePrefix; $productMarkerArray = $this->generateMarkerArray($basketItem->getProductAssocArray(''), $lokalTsProduct, 'product_', 'tx_commerce_products'); $articleMarkerArray = $this->generateMarkerArray($basketItem->getArticleAssocArray(''), $lokalTsArticle, 'article_', 'tx_commerce_articles'); $this->selectAttributes = $basketItem->getProduct()->getAttributes(array(ATTRIB_SELECTOR)); $productMarkerArray['PRODUCT_BASKET_FOR_LISTVIEW'] = $this->makeArticleView($basketItem->getArticle(), $basketItem->getProduct()); $templateSelector = $changerowcount % 2; foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'changeProductTemplate')) { $templateMarker = $hookObj->changeProductTemplate($templateMarker, $basketItem, $this); } } $template = $this->cObj->getSubpart($this->getTemplateCode(), $templateMarker[$templateSelector]); $changerowcount++; $template = $this->cObj->substituteSubpart($template, '###PRODUCT_BASKET_FORM_SMALL###', ''); $markerArray = array_merge($productMarkerArray, $articleMarkerArray); foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'additionalMarkerProductList')) { $markerArray = $hookObj->additionalMarkerProductList($markerArray, $basketItem, $this); } } $tempContent = $this->cObj->substituteMarkerArray($template, $markerArray, '###|###', 1); $content .= $this->substituteMarkerArrayNoCached($tempContent, $this->languageMarker, array(), $wrapMarkerArray); } else { // Remove article from basket $this->basket->deleteArticle($basketItem->getArticle()->getUid()); $this->basket->storeData(); } } return $content; }
/** * Save an order in the given folder * Order-ID has to be calculated beforehand! * * @param int $orderId Uid of the order * @param int $pid Uid of the folder to save the order in * @param Tx_Commerce_Domain_Model_Basket $basket Basket object of the user * @param Tx_Commerce_Payment_Interface_Payment $paymentObj Payment Object * @param bool $doHook Flag if the hooks should be executed * @param bool $doStock Flag if stock reduce should be executed * * @return array $orderData Array with all the order data */ public function saveOrder($orderId, $pid, Tx_Commerce_Domain_Model_Basket $basket, Tx_Commerce_Payment_Interface_Payment $paymentObj, $doHook = TRUE, $doStock = TRUE) { $database = $this->getDatabaseConnection(); // Save addresses with reference to the pObj - which is an instance of pi3 $uids = array(); $types = $database->exec_SELECTgetRows('name', 'tx_commerce_address_types', '1'); foreach ($types as $type) { $uids[$type['name']] = $this->handleAddress($type['name']); } // Generate an order id on the fly if none was passed if (empty($orderId)) { $orderId = uniqid('', TRUE); } // create backend user for inserting the order data $orderData = array(); $orderData['cust_deliveryaddress'] = isset($uids['delivery']) && !empty($uids['delivery']) ? $uids['delivery'] : $uids['billing']; $orderData['cust_invoice'] = $uids['billing']; $orderData['paymenttype'] = $this->getPaymentType(TRUE); $orderData['sum_price_net'] = $basket->getSumNet(); $orderData['sum_price_gross'] = $basket->getSumGross(); $orderData['order_sys_language_uid'] = $this->getFrontendController()->config['config']['sys_language_uid']; $orderData['pid'] = $pid; $orderData['order_id'] = $orderId; $orderData['crdate'] = $GLOBALS['EXEC_TIME']; $orderData['tstamp'] = $GLOBALS['EXEC_TIME']; $orderData['cu_iso_3_uid'] = $this->conf['currencyId']; $orderData['comment'] = GeneralUtility::removeXSS(strip_tags($this->piVars['comment'])); if (is_array($GLOBALS['TSFE']->fe_user->user)) { $orderData['cust_fe_user'] = $GLOBALS['TSFE']->fe_user->user['uid']; } // Get hook objects $hookObjectsArr = array(); if ($doHook) { $hookObjectsArr = $this->getHookObjectArray('finishIt'); // Insert order foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'preinsert')) { $hookObj->preinsert($orderData, $this); } } } $this->debug($orderData, '$orderData', __FILE__ . ' ' . __LINE__); $tceMain = $this->getInstanceOfTceMain($pid); $data = array(); if (isset($this->conf['lockOrderIdInGenerateOrderId']) && $this->conf['lockOrderIdInGenerateOrderId'] == 1) { $data['tx_commerce_orders'][(int) $this->orderUid] = $orderData; $tceMain->start($data, array()); $tceMain->process_datamap(); } else { $newUid = uniqid('NEW'); $data['tx_commerce_orders'][$newUid] = $orderData; $tceMain->start($data, array()); $tceMain->process_datamap(); $this->orderUid = $tceMain->substNEWwithIDs[$newUid]; } // make orderUid avaible in hookObjects $orderUid = $this->orderUid; // Call update method from the payment class $paymentObj->updateOrder($orderUid, $this->sessionData); // Insert order foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'modifyBasketPreSave')) { $hookObj->modifyBasketPreSave($basket, $this); } } // Save order articles if (is_array($basket->getBasketItems())) { /** * Basket item * * @var $basketItem Tx_Commerce_Domain_Model_BasketItem */ foreach ($basket->getBasketItems() as $artUid => $basketItem) { /** * Article * * @var $article Tx_Commerce_Domain_Model_Article */ $article = $basketItem->article; $this->debug($article, '$article', __FILE__ . ' ' . __LINE__); $orderArticleData = array(); $orderArticleData['pid'] = $orderData['pid']; $orderArticleData['crdate'] = $GLOBALS['EXEC_TIME']; $orderArticleData['tstamp'] = $GLOBALS['EXEC_TIME']; $orderArticleData['article_uid'] = $artUid; $orderArticleData['article_type_uid'] = $article->getArticleTypeUid(); $orderArticleData['article_number'] = $article->getOrdernumber(); $orderArticleData['title'] = $basketItem->getTitle(); $orderArticleData['subtitle'] = $article->getSubtitle(); $orderArticleData['price_net'] = $basketItem->getPriceNet(); $orderArticleData['price_gross'] = $basketItem->getPriceGross(); $orderArticleData['tax'] = $basketItem->getTax(); $orderArticleData['amount'] = $basketItem->getQuantity(); $orderArticleData['order_uid'] = $orderUid; $orderArticleData['order_id'] = $orderId; $this->debug($orderArticleData, '$orderArticleData', __FILE__ . ' ' . __LINE__); $newUid = 0; foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'modifyOrderArticlePreSave')) { $hookObj->modifyOrderArticlePreSave($newUid, $orderArticleData, $this, $basketItem); } } if ($this->conf['useStockHandling'] == 1 && $doStock == TRUE) { $article->reduceStock($basketItem->getQuantity()); } if (!$newUid) { $newUid = uniqid('NEW'); } $data = array(); $data['tx_commerce_order_articles'][$newUid] = $orderArticleData; $tceMain->start($data, array()); $tceMain->process_datamap(); $newUid = $tceMain->substNEWwithIDs[$newUid]; foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'modifyOrderArticlePostSave')) { $hookObj->modifyOrderArticlePostSave($newUid, $orderArticleData, $this); } } } } unset($backendUser); return $orderData; }
/** * Renders from the given Basket the Sum Information to HTML-Code * This Method will not replace the Subpart, you have to replace your subpart * in your template by you own * * @param Tx_Commerce_Domain_Model_Basket $basketObj Basket * @param string $subpartTemplate Subpart Template Subpart * * @return string $content HTML-Ccontent from the given Subpart * @abstract * Renders the following MARKER * ###LABEL_SUM_ARTICLE_NET### ###SUM_ARTICLE_NET### * ###LABEL_SUM_ARTICLE_GROSS### ###SUM_ARTICLE_GROSS### * ###LABEL_SUM_SHIPPING_NET### ###SUM_SHIPPING_NET### * ###LABEL_SUM_SHIPPING_GROSS### ###SUM_SHIPPING_GROSS### * ###LABEL_SUM_NET### * ###SUM_NET### * ###LABEL_SUM_TAX### * ###SUM_TAX### * ###LABEL_SUM_GROSS### ###SUM_GROSS### */ public function makeBasketInformation(Tx_Commerce_Domain_Model_Basket $basketObj, $subpartTemplate) { $template = $this->cObj->getSubpart($this->templateCode, $subpartTemplate); $basketObj->recalculateSums(); $markerArray['###SUM_NET###'] = Tx_Commerce_ViewHelpers_Money::format($basketObj->getSumNet(), $this->currency, $this->showCurrency); $markerArray['###SUM_GROSS###'] = Tx_Commerce_ViewHelpers_Money::format($basketObj->getSumGross(), $this->currency, $this->showCurrency); $sumArticleNet = 0; $sumArticleGross = 0; $regularArticleTypes = GeneralUtility::intExplode(',', $this->conf['regularArticleTypes']); foreach ($regularArticleTypes as $regularArticleType) { $sumArticleNet += $basketObj->getArticleTypeSumNet($regularArticleType); $sumArticleGross += $basketObj->getArticleTypeSumGross($regularArticleType); } $markerArray['###SUM_ARTICLE_NET###'] = Tx_Commerce_ViewHelpers_Money::format($sumArticleNet, $this->currency, $this->showCurrency); $markerArray['###SUM_ARTICLE_GROSS###'] = Tx_Commerce_ViewHelpers_Money::format($sumArticleGross, $this->currency, $this->showCurrency); $markerArray['###SUM_SHIPPING_NET###'] = Tx_Commerce_ViewHelpers_Money::format($basketObj->getArticleTypeSumNet(DELIVERYARTICLETYPE), $this->currency, $this->showCurrency); $markerArray['###SUM_SHIPPING_GROSS###'] = Tx_Commerce_ViewHelpers_Money::format($basketObj->getArticleTypeSumGross(DELIVERYARTICLETYPE), $this->currency, $this->showCurrency); $markerArray['###SHIPPING_TITLE###'] = $basketObj->getFirstArticleTypeTitle(DELIVERYARTICLETYPE); $markerArray['###SUM_PAYMENT_NET###'] = Tx_Commerce_ViewHelpers_Money::format($basketObj->getArticleTypeSumNet(PAYMENTARTICLETYPE), $this->currency, $this->showCurrency); $markerArray['###SUM_PAYMENT_GROSS###'] = Tx_Commerce_ViewHelpers_Money::format($basketObj->getArticleTypeSumGross(PAYMENTARTICLETYPE), $this->currency, $this->showCurrency); $markerArray['###PAYMENT_TITLE###'] = $basketObj->getFirstArticleTypeTitle(PAYMENTARTICLETYPE); $markerArray['###PAYMENT_DESCRIPTION###'] = $basketObj->getFirstArticleTypeDescription(PAYMENTARTICLETYPE); $markerArray['###SUM_TAX###'] = Tx_Commerce_ViewHelpers_Money::format($basketObj->getTaxSum(), $this->currency, $this->showCurrency); $taxRateTemplate = $this->cObj->getSubpart($template, '###TAX_RATE_SUMS###'); $taxRates = $basketObj->getTaxRateSums(); $taxRateRows = ''; foreach ($taxRates as $taxRate => $taxRateSum) { $taxRowArray = array(); $taxRowArray['###TAX_RATE###'] = $taxRate; $taxRowArray['###TAX_RATE_SUM###'] = Tx_Commerce_ViewHelpers_Money::format($taxRateSum, $this->currency, $this->showCurrency); $taxRateRows .= $this->cObj->substituteMarkerArray($taxRateTemplate, $taxRowArray); } /** * Hook for processing Taxes */ $hookObjectsArr = array(); if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['makeBasketInformation'])) { GeneralUtility::deprecationLog(' hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/lib/class.tx_commerce_pibase.php\'][\'makeBasketInformation\'] 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/BaseController.php\'][\'makeBasketInformation\'] '); foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['makeBasketInformation'] as $classRef) { $hookObjectsArr[] = GeneralUtility::getUserObj($classRef); } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BaseController.php']['makeBasketInformation'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BaseController.php']['makeBasketInformation'] as $classRef) { $hookObjectsArr[] = GeneralUtility::getUserObj($classRef); } } foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'processMarkerTaxInformation')) { $taxRateRows = $hookObj->processMarkerTaxInformation($taxRateTemplate, $basketObj, $this); } } $template = $this->cObj->substituteSubpart($template, '###TAX_RATE_SUMS###', $taxRateRows); /** * Hook for processing Marker Array */ foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'processMarkerBasketInformation')) { $markerArray = $hookObj->processMarkerBasketInformation($markerArray, $basketObj, $this); } } $content = $this->cObj->substituteMarkerArray($template, $markerArray); $content = $this->cObj->substituteMarkerArray($content, $this->languageMarker); return $content; }