Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
    /**
     * Generates HTML-Code of the basket and stores content
     *
     * @return void
     */
    public function generateBasket()
    {
        $template = $this->cObj->getSubpart($this->getTemplateCode(), '###BASKET###');
        // Render locked information
        if ($this->basket->getReadOnly()) {
            $basketSubpart = $this->cObj->getSubpart($template, 'BASKETLOCKED');
            $template = $this->cObj->substituteSubpart($template, 'BASKETLOCKED', $basketSubpart);
        } else {
            $template = $this->cObj->substituteSubpart($template, 'BASKETLOCKED', '');
        }
        $basketArray['###BASKET_PRODUCT_LIST###'] = $this->makeProductList();
        // Generate basket hooks
        $hookObject = NULL;
        if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['generateBasket'])) {
            GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi2/class.tx_commerce_pi2.php\'][\'generateBasket\']
				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\'][\'generateBasket\']
			');
            $hookObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['generateBasket']);
        }
        if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['generateBasket'])) {
            $hookObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['generateBasket']);
        }
        // No delivery article is present, so draw selector
        $contentDelivery = $this->cObj->getSubpart($this->getTemplateCode(), '###DELIVERYBOX###');
        if (method_exists($hookObject, 'makeDelivery')) {
            $contentDelivery = $hookObject->makeDelivery($this, $this->basket, $contentDelivery);
            $template = $this->cObj->substituteSubpart($template, '###DELIVERYBOX###', $contentDelivery);
        } else {
            $deliveryArray = $this->makeDelivery();
            $contentDelivery = $this->cObj->substituteMarkerArray($contentDelivery, $deliveryArray);
            $template = $this->cObj->substituteSubpart($template, '###DELIVERYBOX###', $contentDelivery);
        }
        $contentPayment = $this->cObj->getSubpart($this->getTemplateCode(), '###PAYMENTBOX###');
        if (method_exists($hookObject, 'makePayment')) {
            $contentPayment = $hookObject->makePayment($this, $this->basket, $contentPayment);
            $template = $this->cObj->substituteSubpart($template, '###PAYMENTBOX###', $contentPayment);
        } else {
            $paymentArray = $this->makePayment();
            $contentPayment = $this->cObj->substituteMarkerArray($contentPayment, $paymentArray);
            $template = $this->cObj->substituteSubpart($template, '###PAYMENTBOX###', $contentPayment);
        }
        $taxRateTemplate = $this->cObj->getSubpart($template, '###TAX_RATE_SUMS###');
        $taxRates = $this->basket->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);
            $taxRateRows .= $this->cObj->substituteMarkerArray($taxRateTemplate, $taxRowArray);
        }
        $template = $this->cObj->substituteSubpart($template, '###TAX_RATE_SUMS###', $taxRateRows);
        $basketArray['###BASKET_NET_PRICE###'] = Tx_Commerce_ViewHelpers_Money::format($this->basket->getSumNet(), $this->currency);
        $basketArray['###BASKET_GROSS_PRICE###'] = Tx_Commerce_ViewHelpers_Money::format($this->basket->getSumGross(), $this->currency);
        $basketArray['###BASKET_TAX_PRICE###'] = Tx_Commerce_ViewHelpers_Money::format($this->basket->getSumGross() - $this->basket->getSumNet(), $this->currency);
        $basketArray['###BASKET_VALUE_ADDED_TAX###'] = Tx_Commerce_ViewHelpers_Money::format($this->basket->getSumGross() - $this->basket->getSumNet(), $this->currency);
        $basketArray['###BASKET_ITEMS###'] = $this->basket->getItemsCount();
        $basketArray['###DELBASKET###'] = $this->pi_linkTP_keepPIvars($this->pi_getLL('delete_basket', 'delete basket'), array('delBasket' => 1), 0, 1);
        $basketArray['###BASKET_NEXTBUTTON###'] = $this->cObj->stdWrap($this->makeCheckOutLink(), $this->conf['nextbutton.']);
        $basketArray['###BASKET_ARTICLES_NET_SUM###'] = Tx_Commerce_ViewHelpers_Money::format($this->basket->getArticleTypeSumNet(NORMALARTICLETYPE), $this->currency);
        $basketArray['###BASKET_ARTICLES_GROSS_SUM###'] = Tx_Commerce_ViewHelpers_Money::format($this->basket->getArticleTypeSumGross(NORMALARTICLETYPE), $this->currency);
        $basketArray['###BASKET_DELIVERY_NET_SUM###'] = Tx_Commerce_ViewHelpers_Money::format($this->basket->getArticleTypeSumNet(DELIVERYARTICLETYPE), $this->currency);
        $basketArray['###BASKET_DELIVERY_GROSS_SUM###'] = Tx_Commerce_ViewHelpers_Money::format($this->basket->getArticleTypeSumGross(DELIVERYARTICLETYPE), $this->currency);
        $basketArray['###BASKET_PAYMENT_NET_SUM###'] = Tx_Commerce_ViewHelpers_Money::format($this->basket->getArticleTypeSumNet(PAYMENTARTICLETYPE), $this->currency);
        $basketArray['###BASKET_PAYMENT_GROSS_SUM###'] = Tx_Commerce_ViewHelpers_Money::format($this->basket->getArticleTypeSumGross(PAYMENTARTICLETYPE), $this->currency);
        $basketArray['###BASKET_PAYMENT_ITEMS###'] = $this->basket->getArticleTypeCount(PAYMENTARTICLETYPE);
        $basketArray['###BASKET_DELIVERY_ITEMS###'] = $this->basket->getArticleTypeCount(DELIVERYARTICLETYPE);
        $basketArray['###BASKET_ARTICLES_ITEMS###'] = $this->basket->getArticleTypeCount(NORMALARTICLETYPE);
        $this->pi_linkTP('', array(), 0, $this->conf['basketPid']);
        $basketArray['###BASKETURL###'] = $this->cObj->lastTypoLinkUrl;
        $this->pi_linkTP('', array(), 0, $this->conf['checkoutPid']);
        $basketArray['###URL_CHECKOUT###'] = $this->cObj->lastTypoLinkUrl;
        $basketArray['###NO_STOCK_MESSAGE###'] = $this->noStock;
        $basketArray['###BASKET_LASTPRODUCTURL###'] = $this->cObj->stdWrap($this->getFrontendController()->fe_user->getKey('ses', 'tx_commerce_lastproducturl'), $this->conf['lastProduct']);
        if ($this->getPriceLimitForBasket() == 1 && $this->conf['priceLimitForBasketMessage']) {
            $basketArray['###BASKET_PRICELIMIT###'] = $this->cObj->cObjGetSingle($this->conf['priceLimitForBasketMessage'], $this->conf['priceLimitForBasketMessage.']);
        } else {
            $basketArray['###BASKET_PRICELIMIT###'] = '';
        }
        $basketArray = array_merge($basketArray, $this->languageMarker);
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['generateBasketMarker'])) {
            GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi2/class.tx_commerce_pi2.php\'][\'generateBasketMarker\']
				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\'][\'generateBasketMarker\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['generateBasketMarker'] as $classRef) {
                $hookObj =& GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'additionalMarker')) {
                    $basketArray = $hookObj->additionalMarker($basketArray, $this, $template);
                }
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['generateBasketMarker'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['generateBasketMarker'] as $classRef) {
                $hookObj =& GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'additionalMarker')) {
                    $basketArray = $hookObj->additionalMarker($basketArray, $this, $template);
                }
            }
        }
        $this->setContent($this->cObj->substituteMarkerArray($template, $basketArray));
        $markerArrayGlobal = $this->addFormMarker(array());
        $this->setContent($this->cObj->substituteMarkerArray($this->getContent(), $markerArrayGlobal, '###|###'));
    }
Exemplo n.º 3
0
    /**
     * 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;
    }