/** * 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 \CommerceTeam\Commerce\Domain\Model\Basket $basket Basket object * * @return bool Check if everything was ok */ public function finishingFunction(array $config = array(), array $session = array(), \CommerceTeam\Commerce\Domain\Model\Basket $basket = null) { /** * Payment library. * * @var \CommerceTeam\Commerce\Payment\Payment $paymentLib */ $paymentLib = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('CommerceTeam\\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 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 Basket $basket 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(Basket $basket, $subpartTemplate) { $template = $this->cObj->getSubpart($this->templateCode, $subpartTemplate); $basket->recalculateSums(); $markerArray['###SUM_NET###'] = Money::format($basket->getSumNet(), $this->currency, $this->showCurrency); $markerArray['###SUM_GROSS###'] = Money::format($basket->getSumGross(), $this->currency, $this->showCurrency); $sumArticleNet = 0; $sumArticleGross = 0; $regularArticleTypes = GeneralUtility::intExplode(',', $this->conf['regularArticleTypes']); foreach ($regularArticleTypes as $regularArticleType) { $sumArticleNet += $basket->getArticleTypeSumNet($regularArticleType); $sumArticleGross += $basket->getArticleTypeSumGross($regularArticleType); } $markerArray['###SUM_ARTICLE_NET###'] = Money::format($sumArticleNet, $this->currency, $this->showCurrency); $markerArray['###SUM_ARTICLE_GROSS###'] = Money::format($sumArticleGross, $this->currency, $this->showCurrency); $markerArray['###SUM_SHIPPING_NET###'] = Money::format($basket->getArticleTypeSumNet(DELIVERYARTICLETYPE), $this->currency, $this->showCurrency); $markerArray['###SUM_SHIPPING_GROSS###'] = Money::format($basket->getArticleTypeSumGross(DELIVERYARTICLETYPE), $this->currency, $this->showCurrency); $markerArray['###SHIPPING_TITLE###'] = $basket->getFirstArticleTypeTitle(DELIVERYARTICLETYPE); $markerArray['###SUM_PAYMENT_NET###'] = Money::format($basket->getArticleTypeSumNet(PAYMENTARTICLETYPE), $this->currency, $this->showCurrency); $markerArray['###SUM_PAYMENT_GROSS###'] = Money::format($basket->getArticleTypeSumGross(PAYMENTARTICLETYPE), $this->currency, $this->showCurrency); $markerArray['###PAYMENT_TITLE###'] = $basket->getFirstArticleTypeTitle(PAYMENTARTICLETYPE); $markerArray['###PAYMENT_DESCRIPTION###'] = $basket->getFirstArticleTypeDescription(PAYMENTARTICLETYPE); $markerArray['###SUM_TAX###'] = Money::format($basket->getTaxSum(), $this->currency, $this->showCurrency); $taxRateTemplate = $this->cObj->getSubpart($template, '###TAX_RATE_SUMS###'); $taxRates = $basket->getTaxRateSums(); $taxRateRows = ''; foreach ($taxRates as $taxRate => $taxRateSum) { $taxRowArray = array(); $taxRowArray['###TAX_RATE###'] = $taxRate; $taxRowArray['###TAX_RATE_SUM###'] = Money::format($taxRateSum, $this->currency, $this->showCurrency); $taxRateRows .= $this->cObj->substituteMarkerArray($taxRateTemplate, $taxRowArray); } /* * Hook for processing Taxes */ $hooks = HookFactory::getHooks('Controller/BaseController', 'makeBasketInformation'); foreach ($hooks as $hook) { if (method_exists($hook, 'processMarkerTaxInformation')) { $taxRateRows = $hook->processMarkerTaxInformation($taxRateTemplate, $basket, $this); } } $template = $this->cObj->substituteSubpart($template, '###TAX_RATE_SUMS###', $taxRateRows); /* * Hook for processing Marker Array */ foreach ($hooks as $hook) { if (method_exists($hook, 'processMarkerBasketInformation')) { $markerArray = $hook->processMarkerBasketInformation($markerArray, $basket, $this); } } $content = $this->cObj->substituteMarkerArray($template, $markerArray); $content = $this->cObj->substituteMarkerArray($content, $this->languageMarker); return $content; }
/** * Renders the product list for the basket. * * @return string HTML Content */ protected function makeProductList() { $content = ''; $hooks = HookFactory::getHooks('Controller/BasketController', 'makeProductList'); $hookObject = HookFactory::getHook('Controller/BasketController', 'alternativePrefixId'); if (is_object($hookObject) && method_exists($hookObject, 'singleDisplayPrefixId')) { $altPrefixSingle = $hookObject->singleDisplayPrefixId(); } 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 \CommerceTeam\Commerce\Domain\Model\BasketItem $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 ($hooks 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 ($hooks 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 \CommerceTeam\Commerce\Domain\Model\Basket $basket Basket object of the user * @param \CommerceTeam\Commerce\Payment\PaymentInterface $paymentObj Payment * @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, \CommerceTeam\Commerce\Domain\Model\Basket $basket, \CommerceTeam\Commerce\Payment\PaymentInterface $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(); if (isset($uids['delivery']) && !empty($uids['delivery'])) { $orderData['cust_deliveryaddress'] = $uids['delivery']; } else { $orderData['cust_deliveryaddress'] = $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()->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($this->getFrontendUser()->user)) { $orderData['cust_fe_user'] = $this->getFrontendUser()->user['uid']; } // Get hook objects $hooks = array(); if ($doHook) { $hooks = HookFactory::getHooks('Controller/CheckoutController', 'saveOrder'); // Insert order foreach ($hooks 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 ($hooks as $hookObj) { if (method_exists($hookObj, 'modifyBasketPreSave')) { $hookObj->modifyBasketPreSave($basket, $this); } } // Save order articles if (is_array($basket->getBasketItems())) { /** * Basket item. * * @var \CommerceTeam\Commerce\Domain\Model\BasketItem $basketItem */ foreach ($basket->getBasketItems() as $artUid => $basketItem) { /** * Article. * * @var \CommerceTeam\Commerce\Domain\Model\Article $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 ($hooks 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 ($hooks as $hookObj) { if (method_exists($hookObj, 'modifyOrderArticlePostSave')) { $hookObj->modifyOrderArticlePostSave($newUid, $orderArticleData, $this); } } } } unset($backendUser); return $orderData; }