/**
  * 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 = HookFactory::getHook('Controller/BasketController', 'generateBasket');
     // No delivery article is present, so draw selector
     $contentDelivery = $this->cObj->getSubpart($this->getTemplateCode(), '###DELIVERYBOX###');
     if (is_object($hookObject) && 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 (is_object($hookObject) && 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###'] = Money::format($taxRateSum, $this->currency);
         $taxRateRows .= $this->cObj->substituteMarkerArray($taxRateTemplate, $taxRowArray);
     }
     $template = $this->cObj->substituteSubpart($template, '###TAX_RATE_SUMS###', $taxRateRows);
     $basketArray['###BASKET_NET_PRICE###'] = Money::format($this->basket->getSumNet(), $this->currency);
     $basketArray['###BASKET_GROSS_PRICE###'] = Money::format($this->basket->getSumGross(), $this->currency);
     $basketArray['###BASKET_TAX_PRICE###'] = Money::format($this->basket->getSumGross() - $this->basket->getSumNet(), $this->currency);
     $basketArray['###BASKET_VALUE_ADDED_TAX###'] = 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###'] = Money::format($this->basket->getArticleTypeSumNet(NORMALARTICLETYPE), $this->currency);
     $basketArray['###BASKET_ARTICLES_GROSS_SUM###'] = Money::format($this->basket->getArticleTypeSumGross(NORMALARTICLETYPE), $this->currency);
     $basketArray['###BASKET_DELIVERY_NET_SUM###'] = Money::format($this->basket->getArticleTypeSumNet(DELIVERYARTICLETYPE), $this->currency);
     $basketArray['###BASKET_DELIVERY_GROSS_SUM###'] = Money::format($this->basket->getArticleTypeSumGross(DELIVERYARTICLETYPE), $this->currency);
     $basketArray['###BASKET_PAYMENT_NET_SUM###'] = Money::format($this->basket->getArticleTypeSumNet(PAYMENTARTICLETYPE), $this->currency);
     $basketArray['###BASKET_PAYMENT_GROSS_SUM###'] = 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);
     $hooks = HookFactory::getHooks('Controller/BasketController', 'generateBasketMarker');
     foreach ($hooks as $hookObject) {
         if (method_exists($hookObject, 'additionalMarker')) {
             $basketArray = $hookObject->additionalMarker($basketArray, $this, $template);
         }
     }
     $this->setContent($this->cObj->substituteMarkerArray($template, $basketArray));
     $markerArrayGlobal = $this->addFormMarker(array());
     $this->setContent($this->cObj->substituteMarkerArray($this->getContent(), $markerArrayGlobal, '###|###'));
 }
示例#2
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 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;
 }
 /**
  * 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;
 }