Exemplo n.º 1
0
 /**
  * Load the deliveryArticle
  *
  * @param Tx_Commerce_Domain_Model_Article $article Article
  *
  * @return Tx_Commerce_Domain_Model_Article $result
  */
 protected function getDeliveryArticle(Tx_Commerce_Domain_Model_Article &$article)
 {
     $deliveryConf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][COMMERCE_EXTKEY]['SYSPRODUCTS']['DELIVERY']['types'];
     $classname = array_shift(array_keys($deliveryConf));
     $database = $this->getDatabaseConnection();
     $row = $database->exec_SELECTgetSingleRow('uid', 'tx_commerce_articles', 'classname = \'' . $classname . '\'');
     $result = FALSE;
     if (!empty($row)) {
         /**
          * Instantiate article class
          *
          * @var Tx_Commerce_Domain_Model_Article $deliveryArticle
          */
         $deliveryArticle = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Article', $row['uid'], $article->getLang());
         /**
          * Do not call loadData at this point, since loadData recalls this hook,
          * so we have a non endingrecursion
          */
         if (is_object($deliveryArticle)) {
             $deliveryArticle->loadPrices();
         }
         $result = $deliveryArticle;
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Change the basket item quantity
  *
  * @param int $quantity Quantity
  *
  * @return true
  */
 public function changeQuantity($quantity)
 {
     $this->quantity = $quantity;
     $this->priceid = $this->article->getActualPriceforScaleUid($quantity);
     $this->price = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_ArticlePrice', $this->priceid, $this->lang_uid);
     $this->price->loadData();
     $this->priceNet = $this->price->getPriceNet();
     $this->priceGross = $this->price->getPriceGross();
     $this->recalculateItemSums();
     return TRUE;
 }
Exemplo n.º 3
0
    /**
     * Make article view
     *
     * @param Tx_Commerce_Domain_Model_Article $article Article
     * @param Tx_Commerce_Domain_Model_Product $product Product
     *
     * @return string
     */
    public function makeArticleView(Tx_Commerce_Domain_Model_Article $article, Tx_Commerce_Domain_Model_Product $product)
    {
        // Getting the select attributes for view
        $attCode = '';
        if (is_object($product)) {
            $attributeArray = $product->getAttributeMatrix(array($article->getUid()), $this->selectAttributes);
            if (is_array($attributeArray)) {
                $templateAttr = $this->cObj->getSubpart($this->getTemplateCode(), '###BASKET_SELECT_ATTRIBUTES###');
                foreach ($attributeArray as $attributeUid => $myAttribute) {
                    /**
                     * Attribute
                     *
                     * @var $attributeObj Tx_Commerce_Domain_Model_Attribute
                     */
                    $attributeObj = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Attribute', $attributeUid, $this->getFrontendController()->tmpl->setup['config.']['sys_language_uid']);
                    $attributeObj->loadData();
                    $markerArray['###SELECT_ATTRIBUTES_TITLE###'] = $myAttribute['title'];
                    $value = current(array_slice(each($myAttribute['values']), 1, 1));
                    $markerArray['###SELECT_ATTRIBUTES_VALUE###'] = $value['value'];
                    $markerArray['###SELECT_ATTRIBUTES_UNIT###'] = $myAttribute['unit'];
                    $attCode .= $this->cObj->substituteMarkerArray($templateAttr, $markerArray);
                }
            }
        }
        /**
         * Basket item
         *
         * @var Tx_Commerce_Domain_Model_BasketItem $basketItem
         */
        $basketItem = $this->basket->getBasketItem($article->getUid());
        $tmpArray = $this->generateMarkerArray($article->returnAssocArray(), (array) $this->conf['articleTS.'], 'article_', 'tx_commerce_articles');
        $markerArray = array();
        foreach ($tmpArray as $key => $value) {
            if (strpos($key, '#') === FALSE) {
                $markerArray['###' . $key . '###'] = $value;
            }
        }
        unset($tmpArray);
        $markerArray['###ARTICLE_SELECT_ATTRIBUTES###'] = $attCode;
        $markerArray['###ARTICLE_UID###'] = $article->getUid();
        $markerArray['###STARTFRM###'] = '<form name="basket_' . $article->getUid() . '" action="' . $this->pi_getPageLink($this->conf['basketPid']) . '" method="post">';
        $markerArray['###HIDDENFIELDS###'] = '<input type="hidden" name="' . $this->prefixId . '[catUid]" value="' . (int) $this->piVars['catUid'] . '" />';
        $markerArray['###HIDDENFIELDS###'] .= '<input type="hidden" name="' . $this->prefixId . '[artAddUid][' . $article->getUid() . '][price_id]" value="' . $basketItem->getPriceUid() . '" />';
        $markerArray['###ARTICLE_HIDDENFIELDS###'] = '<input type="hidden" name="' . $this->prefixId . '[catUid]" value="' . (int) $this->piVars['catUid'] . '" />';
        $markerArray['###ARTICLE_HIDDENFIELDS###'] .= '<input type="hidden" name="' . $this->prefixId . '[artAddUid][' . $article->getUid() . '][price_id]" value="' . $basketItem->getPriceUid() . '" />';
        $markerArray['###QTY_INPUT_VALUE###'] = $basketItem->getQuantity();
        $markerArray['###QTY_INPUT_NAME###'] = $this->prefixId . '[artAddUid][' . $article->getUid() . '][count]';
        $markerArray['###BASKET_ITEM_PRICENET###'] = Tx_Commerce_ViewHelpers_Money::format($basketItem->getPriceNet(), $this->currency);
        $markerArray['###BASKET_ITEM_PRICEGROSS###'] = Tx_Commerce_ViewHelpers_Money::format($basketItem->getPriceGross(), $this->currency);
        $markerArray['###BASKET_ITEM_PRICENETNOSCALE###'] = Tx_Commerce_ViewHelpers_Money::format($basketItem->getNoScalePriceNet(), $this->currency);
        $markerArray['###BASKET_ITEM_PRICEGROSSNOSCALE###'] = Tx_Commerce_ViewHelpers_Money::format($basketItem->getNoScalePriceGross(), $this->currency);
        $markerArray['###BASKET_ITEM_COUNT###'] = $basketItem->getQuantity();
        $markerArray['###BASKET_ITEM_PRICESUM_NET###'] = Tx_Commerce_ViewHelpers_Money::format($basketItem->getItemSumNet(), $this->currency);
        $markerArray['###BASKET_ITEM_PRICESUM_GROSS###'] = Tx_Commerce_ViewHelpers_Money::format($basketItem->getItemSumGross(), $this->currency);
        // Link to delete this article in basket
        if (is_array($this->conf['deleteItem.'])) {
            $typoLinkConf = $this->conf['deleteItem.'];
        } else {
            $typoLinkConf = array();
        }
        $typoLinkConf['parameter'] = $this->conf['basketPid'];
        $typoLinkConf['useCacheHash'] = 1;
        $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[catUid]=' . (int) $this->piVars['catUid'];
        $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[artAddUid][' . $article->getUid() . '][price_id]=' . $basketItem->getPriceUid();
        $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[artAddUid][' . $article->getUid() . '][count]=0';
        // DELIOTMFROMBASKETLINK is deprecated
        $markerArray['###DELETEFROMBASKETLINK###'] = $this->cObj->typoLink($this->pi_getLL('lang_basket_delete_item'), $typoLinkConf);
        $markerArray['###DELIOTMFROMBASKETLINK###'] = $markerArray['###DELETEFROMBASKETLINK###'];
        $templateMarker = '###PRODUCT_BASKET_FORM_SMALL###';
        $template = $this->cObj->getSubpart($this->getTemplateCode(), $templateMarker);
        $markerArray = array_merge($markerArray, $this->languageMarker);
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['makeArticleView'])) {
            GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi2/class.tx_commerce_pi2.php\'][\'makeArticleView\']
				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\'][\'makeArticleView\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['makeArticleView'] as $classRef) {
                $hookObj = GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'additionalMarker')) {
                    $markerArray = $hookObj->additionalMarker($markerArray, $this, $article, $product, $this->basket->getBasketItem($article->getUid()));
                }
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['makeArticleView'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BasketController.php']['makeArticleView'] as $classRef) {
                $hookObj = GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'additionalMarker')) {
                    $markerArray = $hookObj->additionalMarker($markerArray, $this, $article, $product, $this->basket->getBasketItem($article->getUid()));
                }
            }
        }
        $content = $this->cObj->substituteMarkerArray($template, $markerArray);
        return $content;
    }
Exemplo n.º 4
0
    /**
     * Renders the Article Marker and all additional informations needed for
     * a basket form. This Method will not replace the Subpart, you have to
     * replace your subpart in your template by you own
     *
     * @param Tx_Commerce_Domain_Model_Article $article Article the marker based on
     * @param bool $priceid If set true (default) the price-id will be rendered
     *        into the hiddenfields, otherwhise not
     *
     * @return array $markerArray markers needed for the article and the basket form
     */
    public function getArticleMarker(Tx_Commerce_Domain_Model_Article $article, $priceid = FALSE)
    {
        if ($this->handle && is_array($this->conf[$this->handle . '.']) && is_array($this->conf[$this->handle . '.']['articles.'])) {
            $tsconf = $this->conf[$this->handle . '.']['articles.'];
        } else {
            // Set default
            $tsconf = $this->conf['singleView.']['articles.'];
        }
        $markerArray = $this->generateMarkerArray($article->returnAssocArray(), $tsconf, 'article_', 'tx_commerce_article');
        if ($article->getSupplierUid()) {
            $markerArray['ARTICLE_SUPPLIERNAME'] = $article->getSupplierName();
        } else {
            $markerArray['ARTICLE_SUPPLIERNAME'] = '';
        }
        /**
         * STARTFRM and HIDDENFIELDS are old marker, used bevor Version 0.9.3
         * Still existing for compatibility reasons
         * Please use ARTICLE_HIDDENFIEDLS, ARTICLE_FORMACTION
         * and ARTICLE_FORMNAME, ARTICLE_HIDDENCATUID
         */
        $markerArray['STARTFRM'] = '<form name="basket_' . $article->getUid() . '" action="' . $this->pi_getPageLink($this->conf['basketPid']) . '" method="post">';
        $markerArray['HIDDENFIELDS'] = '<input type="hidden" name="' . $this->prefixId . '[catUid]" value="' . $this->category->getUid() . '" />';
        $markerArray['ARTICLE_FORMACTION'] = $this->pi_getPageLink($this->conf['basketPid']);
        $markerArray['ARTICLE_FORMNAME'] = 'basket_' . $article->getUid();
        $markerArray['ARTICLE_HIDDENCATUID'] = '<input type="hidden" name="' . $this->prefixId . '[catUid]" value="' . $this->category->getUid() . '" />';
        $markerArray['ARTICLE_HIDDENFIELDS'] = '';
        /**
         * Build Link to put one of this article in basket
         */
        if ($tsconf['addToBasketLink.']) {
            $typoLinkConf = $tsconf['addToBasketLink.'];
        }
        $typoLinkConf['parameter'] = $this->conf['basketPid'];
        $typoLinkConf['useCacheHash'] = 1;
        $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[catUid]=' . $this->category->getUid();
        if ($priceid == TRUE) {
            $markerArray['ARTICLE_HIDDENFIELDS'] .= '<input type="hidden" name="' . $this->prefixId . '[artAddUid][' . $article->getUid() . '][price_id]" value="' . $article->getPriceUid() . '" />';
            $markerArray['HIDDENFIELDS'] .= '<input type="hidden" name="' . $this->prefixId . '[artAddUid][' . $article->getUid() . '][price_id]" value="' . $article->getPriceUid() . '" />';
            $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[artAddUid][' . $article->getUid() . '][price_id]=' . $article->getPriceUid();
        } else {
            $markerArray['HIDDENFIELDS'] .= '<input type="hidden" name="' . $this->prefixId . '[artAddUid][' . $article->getUid() . '][price_id]" value="" />';
            $markerArray['ARTICLE_HIDDENFIELDS'] .= '<input type="hidden" name="' . $this->prefixId . '[artAddUid][' . $article->getUid() . '][price_id]" value="" />';
            $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[artAddUid][' . $article->getUid() . '][price_id]=';
        }
        $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[artAddUid][' . $article->getUid() . '][count]=1';
        $markerArray['LINKTOPUTINBASKET'] = $this->cObj->typoLink($this->pi_getLL('lang_addtobasketlink'), $typoLinkConf);
        $markerArray['QTY_INPUT_VALUE'] = $this->getArticleAmount($article->getUid(), $tsconf);
        $markerArray['QTY_INPUT_NAME'] = $this->prefixId . '[artAddUid][' . $article->getUid() . '][count]';
        $markerArray['ARTICLE_NUMBER'] = $article->getOrdernumber();
        $markerArray['ARTICLE_ORDERNUMBER'] = $article->getOrdernumber();
        $markerArray['ARTICLE_PRICE_NET'] = Tx_Commerce_ViewHelpers_Money::format($article->getPriceNet(), $this->currency);
        $markerArray['ARTICLE_PRICE_GROSS'] = Tx_Commerce_ViewHelpers_Money::format($article->getPriceGross(), $this->currency);
        $markerArray['DELIVERY_PRICE_NET'] = Tx_Commerce_ViewHelpers_Money::format($article->getDeliveryCostNet(), $this->currency);
        $markerArray['DELIVERY_PRICE_GROSS'] = Tx_Commerce_ViewHelpers_Money::format($article->getDeliveryCostGross(), $this->currency);
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['articleMarker'])) {
            GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/lib/class.tx_commerce_pibase.php\'][\'articleMarker\']
				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\'][\'articleMarker\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['articleMarker'] as $classRef) {
                $hookObj =& GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'additionalMarkerArticle')) {
                    $markerArray = $hookObj->additionalMarkerArticle($markerArray, $article, $this);
                }
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BaseController.php']['articleMarker'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BaseController.php']['articleMarker'] as $classRef) {
                $hookObj =& GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'additionalMarkerArticle')) {
                    $markerArray = $hookObj->additionalMarkerArticle($markerArray, $article, $this);
                }
            }
        }
        return $markerArray;
    }