/** * Constructor * * @param Tx_Commerce_Payment_Interface_Provider $providerObject Parent payment * @param array $options Configuration array * * @return self */ public function __construct(Tx_Commerce_Payment_Interface_Provider $providerObject, array $options = array()) { $this->providerObject = $providerObject; $this->paymentObject = $this->providerObject->getPaymentObject(); $this->pibaseObject = $this->paymentObject->getParentObject(); $this->options = $options; }
/** * Load configured criteria * * @return void * @throws Exception If criteria was not of correct interface */ protected function loadCriteria() { // Get and instantiate registered criteria of this payment provider $criteraConfigurations = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][COMMERCE_EXTKEY]['SYSPRODUCTS']['PAYMENT']['types'][$this->paymentObject->getType()]['provider'][$this->type]['criteria']; if (is_array($criteraConfigurations)) { foreach ($criteraConfigurations as $criterionConfiguration) { if (!is_array($criterionConfiguration['options'])) { $criterionConfiguration['options'] = array(); } /** * Criterion * * @var $criterion Tx_Commerce_Payment_Interface_ProviderCriterion */ $criterion = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($criterionConfiguration['class'], $this, $criterionConfiguration['options']); if (!$criterion instanceof Tx_Commerce_Payment_Interface_ProviderCriterion) { throw new Exception('Criterion ' . $criterionConfiguration['class'] . ' must implement interface Tx_Commerce_Payment_Interface_ProviderCriterion', 1307720945); } $this->criteria[] = $criterion; } } }
/** * 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; }