Example #1
0
    /**
     * This method converts an sends mails.
     *
     * @param array $mailconf Mail configuration
     * @param array $orderdata Order data
     * @param string $template Template
     *
     * @return bool of \TYPO3\CMS\Core\Mail\MailMessage
     */
    protected function ordermoveSendMail(array $mailconf, array &$orderdata, &$template)
    {
        // First line is subject
        $parts = explode(chr(10), $mailconf['plain']['content'], 2);
        // add mail subject
        $mailconf['alternateSubject'] = trim($parts[0]);
        // replace plaintext content
        $mailconf['plain']['content'] = trim($parts[1]);
        /**
         * Convert Text to charset
         */
        $this->csConvObj->initCharset('utf-8');
        $this->csConvObj->initCharset('8bit');
        $mailconf['plain']['content'] = $this->csConvObj->conv($mailconf['plain']['content'], 'utf-8', 'utf-8');
        $mailconf['alternateSubject'] = $this->csConvObj->conv($mailconf['alternateSubject'], 'utf-8', 'utf-8');
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/class.tx_commerce_ordermailhooks.php']['ordermoveSendMail'])) {
            GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Hook/class.tx_commerce_ordermailhooks.php\'][\'ordermoveSendMail\']
				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/Hook/OrdermailHooks.php\'][\'ordermoveSendMail\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/class.tx_commerce_ordermailhooks.php']['ordermoveSendMail'] as $classRef) {
                $hookObj = GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'postOrdermoveSendMail')) {
                    $hookObj->postOrdermoveSendMail($mailconf, $orderdata, $template);
                }
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/OrdermailHooks.php']['ordermoveSendMail'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/OrdermailHooks.php']['ordermoveSendMail'] as $classRef) {
                $hookObj = GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'postOrdermoveSendMail')) {
                    $hookObj->postOrdermoveSendMail($mailconf, $orderdata, $template);
                }
            }
        }
        return Tx_Commerce_Utility_GeneralUtility::sendMail($mailconf);
    }
Example #2
0
 /**
  * Returns if this category has products with stock
  *
  * @return bool TRUE, if this category has products with stock, FALSE if not
  */
 public function hasProductsWithStock()
 {
     $result = FALSE;
     if ($this->hasProducts()) {
         $result = count(Tx_Commerce_Utility_GeneralUtility::removeNoStockProducts($this->getProducts(), 0));
     }
     return $result;
 }
    /**
     * Get all addresses from the database that are assigned to the current user.
     *
     * @param int $userId UID of the user
     * @param int $addressType Type of addresses to retrieve
     *
     * @return array Keys with UIDs and values with complete addresses data
     */
    public function getAddresses($userId, $addressType = 0)
    {
        $select = 'tx_commerce_fe_user_id = ' . (int) $userId . \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tt_address');
        if ($addressType > 0) {
            $select .= ' AND tx_commerce_address_type_id=' . (int) $addressType;
        } elseif (isset($this->conf['selectAddressTypes'])) {
            $select .= ' AND tx_commerce_address_type_id IN (' . $this->conf['selectAddressTypes'] . ')';
        } else {
            $this->addresses = array();
            return array();
        }
        $select .= ' AND deleted=0 AND pid=' . $this->conf['addressPid'];
        /**
         * Hook for adding select statement
         */
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi4/class.tx_commerce_pi4.php']['getAddresses'])) {
            \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi4/class.tx_commerce_pi4.php\'][\'getAddresses\']
				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/AddressesController.php\'][\'getAddresses\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi4/class.tx_commerce_pi4.php']['getAddresses'] as $classRef) {
                $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'editSelectStatement')) {
                    $select = $hookObj->editSelectStatement($select, $userId, $addressType, $this);
                }
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/AddressesController.php']['getAddresses'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/AddressesController.php']['getAddresses'] as $classRef) {
                $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'editSelectStatement')) {
                    $select = $hookObj->editSelectStatement($select, $userId, $addressType, $this);
                }
            }
        }
        $rows = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'tt_address', $select, '', 'tx_commerce_is_main_address desc');
        $result = array();
        foreach ($rows as $address) {
            $result[$address['uid']] = Tx_Commerce_Utility_GeneralUtility::removeXSSStripTagsArray($address);
        }
        return $result;
    }
Example #4
0
 /**
  * Send admin mail
  * Also performes a charset Conversion for the mail, including Sender
  *
  * @param int $orderUid Order ID
  * @param array $orderData Collected Order Data form PI3
  *
  * @return bool TRUE on success
  */
 public function sendAdminMail($orderUid, array $orderData)
 {
     $hookObjectsArr = $this->getHookObjectArray('sendAdminMail');
     if (is_array($GLOBALS['TSFE']->fe_user->user && strlen($GLOBALS['TSFE']->fe_user->user['email']))) {
         $userMail = $GLOBALS['TSFE']->fe_user->user['email'];
     } else {
         $userMail = $this->sessionData['billing']['email'];
     }
     if (is_array($GLOBALS['TSFE']->fe_user->user && strlen($GLOBALS['TSFE']->fe_user->user['email']))) {
         $userName = $GLOBALS['TSFE']->fe_user->user['name'] . ' ' . $GLOBALS['TSFE']->fe_user->user['surname'];
     } else {
         $userName = $this->sessionData['billing']['name'] . ' ' . $this->sessionData['billing']['surname'];
     }
     if ($this->conf['adminmail.']['from'] || $userMail) {
         /**
          * Checkout controller
          *
          * @var $adminMailObj Tx_Commerce_Controller_CheckoutController
          */
         $adminMailObj = GeneralUtility::makeInstance('Tx_Commerce_Controller_CheckoutController');
         $adminMailObj->conf = $this->conf;
         $adminMailObj->pi_setPiVarDefaults();
         $adminMailObj->cObj = $this->cObj;
         $adminMailObj->pi_loadLL();
         $adminMailObj->staticInfo =& $this->staticInfo;
         $adminMailObj->currency = $this->currency;
         $adminMailObj->showCurrency = $this->conf['adminmail.']['showCurrency'];
         $adminMailObj->templateCode = $this->cObj->fileResource($this->conf['adminmail.']['templateFile']);
         $adminMailObj->generateLanguageMarker();
         $adminMailObj->userData = $this->userData;
         foreach ($hookObjectsArr as $hookObj) {
             if (method_exists($hookObj, 'preGenerateMail')) {
                 $hookObj->preGenerateMail($adminMailObj, $this);
             }
         }
         $mailcontent = $adminMailObj->generateMail($orderUid, $orderData);
         /**
          * Basket
          *
          * @var $basket Tx_Commerce_Domain_Model_Basket
          */
         $basket =& $GLOBALS['TSFE']->fe_user->tx_commerce_basket;
         foreach ($hookObjectsArr as $hookObj) {
             if (method_exists($hookObj, 'PostGenerateMail')) {
                 $hookObj->PostGenerateMail($adminMailObj, $this, $basket, $mailcontent, $this);
             }
         }
         $htmlContent = '';
         if ($this->conf['adminmail.']['useHtml'] == '1' && $this->conf['adminmail.']['templateFileHtml']) {
             $adminMailObj->templateCode = $this->cObj->fileResource($this->conf['adminmail.']['templateFileHtml']);
             $htmlContent = $adminMailObj->generateMail($orderUid, $orderData, array());
             $adminMailObj->isHtmlMail = TRUE;
             foreach ($hookObjectsArr as $hookObj) {
                 if (method_exists($hookObj, 'PostGenerateMail')) {
                     $hookObj->PostGenerateMail($adminMailObj, $this, $basket, $htmlContent);
                 }
             }
             unset($adminMailObj->isHtmlMail);
         }
         // Moved to plainMailEncoded
         // First line is subject
         $parts = explode(chr(10), $mailcontent, 2);
         $subject = trim($parts[0]);
         $plainMessage = trim($parts[1]);
         // Check if charset ist set by TS
         // Otherwise set to default Charset
         if (!$this->conf['adminmail.']['charset']) {
             $this->conf['adminmail.']['charset'] = $GLOBALS['TSFE']->renderCharset;
         }
         // Checck if mailencoding ist set
         // Otherwise set to 8bit
         if (!$this->conf['adminmail.']['encoding ']) {
             $this->conf['adminmail.']['encoding '] = '8bit';
         }
         // Convert Text to charset
         $GLOBALS['TSFE']->csConvObj->initCharset($GLOBALS['TSFE']->renderCharset);
         $GLOBALS['TSFE']->csConvObj->initCharset(strtolower($this->conf['adminmail.']['charset']));
         $plainMessage = $GLOBALS['TSFE']->csConvObj->conv($plainMessage, $GLOBALS['TSFE']->renderCharset, strtolower($this->conf['adminmail.']['charset']));
         $subject = $GLOBALS['TSFE']->csConvObj->conv($subject, $GLOBALS['TSFE']->renderCharset, strtolower($this->conf['adminmail.']['charset']));
         $usernameMailencoded = $GLOBALS['TSFE']->csConvObj->specCharsToASCII($GLOBALS['TSFE']->renderCharset, $userName);
         if ($this->debug) {
             print '<b>Adminmail from </b><pre>' . $plainMessage . '</pre>' . LF;
         }
         // Mailconf for tx_commerce_div::sendMail($mailconf);
         $recipient = array();
         if ($this->conf['adminmail.']['cc']) {
             $recipient = GeneralUtility::trimExplode(',', $this->conf['adminmail.']['cc']);
         }
         if (is_array($recipient)) {
             array_push($recipient, $this->conf['adminmail.']['mailto']);
         }
         $mailconf = array('plain' => array('content' => $plainMessage, 'subject' => $subject), 'html' => array('content' => $htmlContent, 'path' => '', 'useHtml' => $this->conf['adminmail.']['useHtml']), 'defaultCharset' => $this->conf['adminmail.']['charset'], 'encoding' => $this->conf['adminmail.']['encoding'], 'attach' => $this->conf['adminmail.']['attach.'], 'alternateSubject' => $this->conf['adminmail.']['alternateSubject'], 'recipient' => implode(',', $recipient), 'recipient_copy' => $this->conf['adminmail.']['bcc'], 'replyTo' => $this->conf['adminmail.']['from'], 'priority' => $this->conf['adminmail.']['priority'], 'callLocation' => 'sendAdminMail', 'additionalData' => $this);
         // Check if user mail is set
         if ($userMail && $usernameMailencoded && $this->conf['adminmail.']['sendAsUser'] == 1) {
             $mailconf['fromEmail'] = $userMail;
             $mailconf['fromName'] = $usernameMailencoded;
         } else {
             $mailconf['fromEmail'] = $this->conf['adminmail.']['from'];
             $mailconf['fromName'] = $this->conf['adminmail.']['from_name'];
         }
         Tx_Commerce_Utility_GeneralUtility::sendMail($mailconf);
         return TRUE;
     }
     return FALSE;
 }
Example #5
0
    /**
     * Inits the main params for using in the script
     *
     * @param array $conf Configuration
     *
     * @return void
     */
    public function init(array $conf = array())
    {
        parent::init($conf);
        // Merge default vars, if other prefix_id
        if ($this->prefixId != 'tx_commerce_pi1') {
            $generellRequestVars = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_commerce');
            if (is_array($generellRequestVars)) {
                foreach ($generellRequestVars as $key => $value) {
                    if (empty($this->piVars[$key])) {
                        $this->piVars[$key] = $value;
                    }
                }
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi1/class.tx_commerce_pi1.php']['init'])) {
            \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi1/class.tx_commerce_pi1.php\'][\'init\']
				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/ListController.php\'][\'init\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi1/class.tx_commerce_pi1.php']['init'] as $classRef) {
                $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'preInit')) {
                    $hookObj->preInit($this);
                }
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['init'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['init'] as $classRef) {
                $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'preInit')) {
                    $hookObj->preInit($this);
                }
            }
        }
        $this->templateFolder = 'uploads/tx_commerce/';
        $this->pi_USER_INT_obj = 0;
        $this->conf['singleProduct'] = (int) $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'product_id', 's_product');
        if ($this->conf['singleProduct'] > 0) {
            // product UID was set by Plugin or TS
            $this->singleViewAsPlugin = TRUE;
        }
        // Unset variable, if smaller than 0, as -1 is returend
        // when no product is selcted in form.
        if ($this->conf['singleProduct'] < 0) {
            $this->conf['singleProduct'] = FALSE;
        }
        $this->piVars['showUid'] = intval($this->piVars['showUid']) ?: 0;
        $this->piVars['showUid'] = $this->piVars['showUid'] ?: $this->conf['singleProduct'];
        $this->handle = $this->piVars['showUid'] ? 'singleView' : 'listView';
        // Define the currency
        // Use of curency is depricated as it was only a typo :-)
        if ($this->conf['curency'] > '') {
            $this->currency = $this->conf['curency'];
        }
        if ($this->conf['currency'] > '') {
            $this->currency = $this->conf['currency'];
        }
        if (empty($this->currency)) {
            $this->currency = 'EUR';
        }
        // Set some flexform values
        $this->master_cat = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'StartCategory', 's_product');
        if (!$this->master_cat) {
            $this->master_cat = $this->conf['catUid'];
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'displayPID', 's_template')) {
            $this->conf['overridePid'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'displayPID', 's_template');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'numberOfTopproducts', 's_product')) {
            $this->conf['numberOfTopproducts'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'numberOfTopproducts', 's_product');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showPageBrowser', 's_template')) {
            $this->conf['showPageBrowser'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showPageBrowser', 's_template');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'maxRecords', 's_template')) {
            $this->conf['maxRecords'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'maxRecords', 's_template');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'maxPages', 's_template')) {
            $this->conf['maxPages'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'maxPages', 's_template');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'basketPid', 's_template')) {
            $this->conf['basketPid'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'basketPid', 's_template');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'dontLinkActivePage', 's_template')) {
            $this->conf['pageBrowser.']['dontLinkActivePage'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'dontLinkActivePage', 's_template');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showFirstLast', 's_template')) {
            $this->conf['pageBrowser.']['showFirstLast'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showFirstLast', 's_template');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showRange', 's_template')) {
            $this->conf['pageBrowser.']['showRange'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showRange', 's_template');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showItemCount', 's_template')) {
            $this->conf['pageBrowser.']['showItemCount'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showItemCount', 's_template');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'hscText', 's_template')) {
            $this->conf['pageBrowser.']['hscText'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'hscText', 's_template');
        }
        if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template', 's_template') && file_exists($this->templateFolder . $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template', 's_template'))) {
            $this->conf['templateFile'] = $this->templateFolder . $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template', 's_template');
            if ($this->cObj->fileResource($this->conf['templateFile'])) {
                $this->templateCode = $this->cObj->fileResource($this->conf['templateFile']);
            }
        }
        $accessible = FALSE;
        /**
         * Temporary category
         *
         * @var Tx_Commerce_Domain_Model_Category $tmpCategory
         */
        $tmpCategory = NULL;
        if ($this->piVars['catUid']) {
            $this->cat = (int) $this->piVars['catUid'];
            $tmpCategory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeinstance('Tx_Commerce_Domain_Model_Category', $this->cat, $this->getFrontendController()->tmpl->setup['config.']['sys_language_uid']);
            $accessible = $tmpCategory->isAccessible();
        }
        // Validate given catUid, if it's given and accessible
        if (!$this->piVars['catUid'] || !$accessible) {
            $this->cat = (int) $this->master_cat;
            $tmpCategory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeinstance('Tx_Commerce_Domain_Model_Category', $this->cat, $this->getFrontendController()->tmpl->setup['config.']['sys_language_uid']);
        }
        if (!isset($this->piVars['catUid'])) {
            $this->piVars['catUid'] = $this->master_cat;
        }
        if (is_object($tmpCategory)) {
            $tmpCategory->loadData();
        }
        $this->category = $tmpCategory;
        $categorySubproducts = $this->category->getProductUids();
        $frontend = $this->getFrontendController();
        if (!$this->conf['singleProduct'] && (int) $this->piVars['showUid'] > 0 && !$GLOBALS['TSFE']->beUserLogin) {
            if (is_array($categorySubproducts)) {
                if (!in_array($this->piVars['showUid'], $categorySubproducts)) {
                    $categoryAllSubproducts = $this->category->getProducts();
                    if (!in_array((int) $this->piVars['showUid'], $categoryAllSubproducts)) {
                        // The requested product is not beblow the selected category
                        // So exit with page not found
                        $frontend->pageNotFoundAndExit($this->pi_getLL('error.productNotFound', 'Product not found', 1));
                    }
                }
            } else {
                $categoryAllSubproducts = $this->category->getProducts();
                if (!in_array($this->piVars['showUid'], $categoryAllSubproducts)) {
                    // The requested product is not beblow the selected category
                    // So exit with page not found
                    $frontend->pageNotFoundAndExit($this->pi_getLL('error.productNotFound', 'Product not found', 1));
                }
            }
        }
        if ($this->piVars['catUid'] && $this->conf['checkCategoryTree'] == 1) {
            // Validate given CAT UID, if is below master_cat
            $this->masterCategoryObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeinstance('Tx_Commerce_Domain_Model_Category', $this->master_cat, $this->getFrontendController()->tmpl->setup['config.']['sys_language_uid']);
            $this->masterCategoryObj->loadData();
            /**
             * Master category
             *
             * @var Tx_Commerce_Domain_Model_Category masterCategoryObj
             */
            $masterCategorySubCategories = $this->masterCategoryObj->getChildCategoriesUidlist();
            if (in_array($this->piVars['catUid'], $masterCategorySubCategories)) {
                $this->cat = (int) $this->piVars['catUid'];
            } else {
                // Wrong UID, so start with page not found
                $frontend->pageNotFoundAndExit($this->pi_getLL('error.categoryNotFound', 'Product not found', 1));
            }
        } elseif (!isset($this->piVars['catUid'])) {
            $this->cat = (int) $this->master_cat;
        }
        if ($this->cat != $this->category->getUid()) {
            // Only, if the category has been changed
            unset($this->category);
            /**
             * Category
             *
             * @var Tx_Commerce_Domain_Model_Category category
             */
            $this->category = \TYPO3\CMS\Core\Utility\GeneralUtility::makeinstance('Tx_Commerce_Domain_Model_Category', $this->cat, $GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid']);
            $this->category->loadData();
        }
        $this->internal['results_at_a_time'] = $this->conf['maxRecords'];
        $this->internal['maxPages'] = $this->conf['maxPages'];
        // Going the long way ??? Just for list view
        $long = 1;
        switch ($this->handle) {
            case 'singleView':
                if ($this->initSingleView($this->piVars['showUid'])) {
                    $long = 0;
                }
                break;
            default:
        }
        if ($this->cat > 0) {
            $this->category_array = $this->category->returnAssocArray();
            $catConf = $this->category->getTyposcriptConfig();
            if (is_array($catConf['catTS.'])) {
                \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->conf, $catConf['catTS.']);
            }
            if ($long) {
                $this->category->setPageTitle();
                $this->category->getChildCategories();
                if ($this->conf['groupProductsByCategory']) {
                    $this->category_products = $this->category->getProducts(0);
                } elseif ($this->conf['showProductsRecLevel']) {
                    $this->category_products = $this->category->getProducts($this->conf['showProductsRecLevel']);
                } else {
                    $this->category_products = $this->category->getProducts(0);
                }
                if ($this->conf['useStockHandling'] == 1) {
                    $this->category_products = Tx_Commerce_Utility_GeneralUtility::removeNoStockProducts($this->category_products, $this->conf['products.']['showWithNoStock']);
                }
                $this->internal['res_count'] = count($this->category_products);
            }
        } else {
            $this->content = $this->cObj->stdWrap($this->conf['emptyCOA'], $this->conf['emptyCOA.']);
            $this->handle = FALSE;
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi1/class.tx_commerce_pi1.php']['postInit'])) {
            \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi1/class.tx_commerce_pi1.php\'][\'postInit\']
				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/ListController.php\'][\'postInit\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi1/class.tx_commerce_pi1.php']['postInit'] as $classRef) {
                $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'postInit')) {
                    $hookObj->postInit($this);
                }
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['postInit'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['postInit'] as $classRef) {
                $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'postInit')) {
                    $hookObj->postInit($this);
                }
            }
        }
    }
Example #6
0
 /**
  * Method for generating the rootlineMenu to use in TS
  *
  * @param string $content Passed to method
  * @param array $conf TS Array
  *
  * @return array for the menurendering of TYPO3
  */
 public function renderRootline($content, array $conf)
 {
     $this->mConf = $this->processConf($conf);
     $this->pid = (int) ($this->mConf['overridePid'] ? $this->mConf['overridePid'] : $GLOBALS['TSFE']->id);
     $this->gpVars = GeneralUtility::_GPmerged($this->prefixId);
     Tx_Commerce_Utility_GeneralUtility::initializeFeUserBasket();
     $this->gpVars['basketHashValue'] = $GLOBALS['TSFE']->fe_user->tx_commerce_basket->getBasketHashValue();
     if (!is_object($this->category)) {
         $this->category = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Category', $this->mConf['category'], $this->getFrontendController()->sys_language_uid);
         $this->category->loadData();
     }
     $returnArray = array();
     $returnArray = $this->getCategoryRootlineforTypoScript($this->gpVars['catUid'], $returnArray);
     /**
      * Add product to rootline, if a product is displayed and showProducts
      * is set via TS
      */
     if ($this->mConf['showProducts'] == 1 && $this->gpVars['showUid'] > 0) {
         /**
          * Product
          *
          * @var Tx_Commerce_Domain_Model_Product $productObject
          */
         $productObject = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Product', $this->gpVars['showUid'], $this->getFrontendController()->sys_language_uid);
         $productObject->loadData();
         /**
          * Category
          *
          * @var Tx_Commerce_Domain_Model_Category $categoryObject
          */
         $categoryObject = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Category', $this->gpVars['catUid'], $this->getFrontendController()->sys_language_uid);
         $categoryObject->loadData();
         $addGetvars = $this->separator . $this->prefixId . '[showUid]=' . $productObject->getUid() . $this->separator . $this->prefixId . '[catUid]=' . $categoryObject->getUid();
         if (is_string($this->gpVars['basketHashValue'])) {
             $addGetvars .= $this->separator . $this->prefixId . '[basketHashValue]=' . $this->gpVars['basketHashValue'];
         }
         $cHash = $this->generateChash($addGetvars . $GLOBALS['TSFE']->linkVars);
         /**
          * Currentyl no Navtitle in tx_commerce_products
          * 'nav_title' => $ProductObject->get_navtitle(),
          */
         if ($productObject->getUid() == $this->gpVars['showUid']) {
             $itemState = 'CUR';
             $itemStateList = 'CUR,NO';
         } else {
             $itemState = 'NO';
             $itemStateList = 'NO';
         }
         $returnArray[] = array('title' => $productObject->getTitle(), 'uid' => $this->pid, '_ADD_GETVARS' => $addGetvars . $this->separator . 'cHash=' . $cHash, 'ITEM_STATE' => $itemState, 'ITEM_STATES_LIST' => $itemStateList, '_PAGES_OVERLAY' => $productObject->getTitle());
     }
     return $returnArray;
 }
 /**
  * Returns the HTML code for the header row
  *
  * @param int $colCount The number of columns we have
  * @param array $acBefore The additional columns before the attribute columns
  * @param array $acAfter The additional columns after the attribute columns
  * @param bool $addTr Add table row
  *
  * @return string The HTML header code
  */
 protected function getHeadRow(&$colCount, array $acBefore = NULL, array $acAfter = NULL, $addTr = TRUE)
 {
     $result = '';
     if ($addTr) {
         $result .= '<tr>';
     }
     if ($acBefore != NULL) {
         $result .= '<th>' . implode('</th><th>', Tx_Commerce_Utility_GeneralUtility::removeXSSStripTagsArray($acBefore)) . '</th>';
     }
     if (is_array($this->attributes['ct1'])) {
         foreach ($this->attributes['ct1'] as $attribute) {
             $result .= '<th>' . htmlspecialchars(strip_tags($attribute['attributeData']['title'])) . '</th>';
             $colCount++;
         }
     }
     if ($acAfter != NULL) {
         $result .= '<th>' . implode('</th><th>', Tx_Commerce_Utility_GeneralUtility::removeXSSStripTagsArray($acAfter)) . '</th>';
     }
     if ($addTr) {
         $result .= '</tr>';
     }
     $colCount += count($acBefore) + count($acAfter);
     return $result;
 }
Example #8
0
 /**
  * This fetches the value for an attribute. It fetches the "default_value"
  * from the table if the attribute has no valuelist, otherwise it fetches
  * the title from the attribute_values table.
  * You can submit only an attribute uid, then the mehod fetches the data
  * from the databse itself, or you submit the data from the relation table
  * and the data from the attribute table if this data is already present.
  *
  * @param int $pUid Product UID
  * @param int $aUid Attribute UID
  * @param string $relationTable Table where the relations between
  * 	prodcts and attributes are stored
  * @param array $relationData Relation dataset between the product
  * 	and the attribute (default NULL)
  * @param array $attributeData Meta data (has_valuelist, unit) for
  * 	the attribute you want to get the value from (default NULL)
  *
  * @return string The value of the attribute. It's maybe appended with the
  * 	unit of the attribute
  */
 public function getAttributeValue($pUid, $aUid, $relationTable, array $relationData = NULL, array $attributeData = NULL)
 {
     $database = self::getDatabaseConnection();
     if ($relationData == NULL || $attributeData == NULL) {
         // data from database if one of the arguments is NULL. This nesccessary
         // to keep the data consistant
         $relRes = $database->exec_SELECTquery('uid_valuelist,default_value,value_char', $relationTable, 'uid_local = ' . (int) $pUid . ' AND uid_foreign = ' . (int) $aUid);
         $relationData = $database->sql_fetch_assoc($relRes);
         $attributeData = $this->getAttributeData($aUid, 'has_valuelist,unit');
     }
     if ($attributeData['has_valuelist'] == '1') {
         if ($attributeData['multiple'] == 1) {
             $result = array();
             if (is_array($relationData)) {
                 foreach ($relationData as $relation) {
                     $valueRes = $database->exec_SELECTquery('value', 'tx_commerce_attribute_values', 'uid = ' . (int) $relation['uid_valuelist'] . $this->enableFields('tx_commerce_attribute_values'));
                     $value = $database->sql_fetch_assoc($valueRes);
                     $result[] = $value['value'];
                 }
             }
             return '<ul><li>' . implode('</li><li>', Tx_Commerce_Utility_GeneralUtility::removeXSSStripTagsArray($result)) . '</li></ul>';
         } else {
             // fetch data from attribute values table
             $valueRes = $database->exec_SELECTquery('value', 'tx_commerce_attribute_values', 'uid = ' . (int) $relationData['uid_valuelist'] . $this->enableFields('tx_commerce_attribute_values'));
             $value = $database->sql_fetch_assoc($valueRes);
             return $value['value'];
         }
     } elseif (!empty($relationData['value_char'])) {
         // the value is in field default_value
         return $relationData['value_char'] . ' ' . $attributeData['unit'];
     }
     return $relationData['default_value'] . ' ' . $attributeData['unit'];
 }
Example #9
0
    /**
     * This method renders a product to a template
     *
     * @param Tx_Commerce_Domain_Model_Product $product Product
     * @param string $template TYPO3 Template
     * @param array $typoscript TypoScript
     * @param array $articleMarker Marker for the article description
     * @param string $articleSubpart Subpart
     *
     * @return string rendered HTML
     */
    public function renderProduct(Tx_Commerce_Domain_Model_Product $product, $template, array $typoscript, array $articleMarker, $articleSubpart = '')
    {
        if (!$product instanceof Tx_Commerce_Domain_Model_Product) {
            return FALSE;
        }
        if (empty($articleMarker)) {
            return $this->error('renderProduct', __LINE__, 'No ArticleMarker defined in renderProduct ');
        }
        $hookObjectsArr = array();
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['product'])) {
            GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/lib/class.tx_commerce_pibase.php\'][\'product\']
				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\'][\'renderProduct\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['product'] as $classRef) {
                $hookObjectsArr[] =& GeneralUtility::getUserObj($classRef);
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BaseController.php']['renderProduct'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BaseController.php']['renderProduct'] as $classRef) {
                $hookObjectsArr[] =& GeneralUtility::getUserObj($classRef);
            }
        }
        $data = $product->returnAssocArray();
        // maybe this is a related product so category may be wrong
        $categoryUid = $this->category->getUid();
        $productCategories = $product->getParentCategories();
        if (!in_array($categoryUid, $productCategories, FALSE)) {
            $categoryUid = $productCategories[0];
        }
        /**
         *  Build TS for Linking the Catergory Images
         */
        $localTs = $typoscript;
        /**
         * Generate TypoLink Configuration and ad to fields by addTypoLinkToTs
         */
        if ($this->conf['overridePid']) {
            $typoLinkConf['parameter'] = $this->conf['overridePid'];
        } else {
            $typoLinkConf['parameter'] = $this->pid;
        }
        $typoLinkConf['useCacheHash'] = 1;
        $typoLinkConf['additionalParams'] = $this->argSeparator . $this->prefixId . '[showUid]=' . $product->getUid();
        $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[catUid]=' . $categoryUid;
        if ($this->basketHashValue) {
            $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[basketHashValue]=' . $this->basketHashValue;
        }
        $localTs = $this->addTypoLinkToTypoScript($localTs, $typoLinkConf);
        $markerArray = $this->generateMarkerArray($data, $localTs, '', 'Tx_Commerce_Domain_Model_Products');
        $markerArrayUp = array();
        foreach ($markerArray as $k => $v) {
            $markerArrayUp[strtoupper($k)] = $v;
        }
        $markerArray = $this->cObj->fillInMarkerArray(array(), $markerArrayUp, implode(',', array_keys($markerArrayUp)), FALSE, 'PRODUCT_');
        $this->can_attributes = $product->getAttributes(array(ATTRIB_CAN));
        $this->selectAttributes = $product->getAttributes(array(ATTRIB_SELECTOR));
        $this->shall_attributes = $product->getAttributes(array(ATTRIB_SHAL));
        $productAttributesSubpartArray = array();
        $productAttributesSubpartArray[] = '###' . strtoupper($this->conf['templateMarker.']['productAttributes']) . '###';
        $productAttributesSubpartArray[] = '###' . strtoupper($this->conf['templateMarker.']['productAttributes2']) . '###';
        $markerArray['###SUBPART_PRODUCT_ATTRIBUTES###'] = $this->cObj->stdWrap($this->renderProductAttributeList($product, $productAttributesSubpartArray, $typoscript['productAttributes.']['fields.']), $typoscript['productAttributes.']);
        $linkArray = array();
        $linkArray['catUid'] = (int) $categoryUid;
        if ($this->basketHashValue) {
            $linkArray['basketHashValue'] = $this->basketHashValue;
        }
        if (is_numeric($this->piVars['manufacturer'])) {
            $linkArray['manufacturer'] = $this->piVars['manufacturer'];
        }
        if (is_numeric($this->piVars['mDepth'])) {
            $linkArray['mDepth'] = $this->piVars['mDepth'];
        }
        foreach ($hookObjectsArr as $hookObj) {
            if (method_exists($hookObj, 'postProcessLinkArray')) {
                $linkArray = $hookObj->postProcessLinkArray($linkArray, $product, $this);
            }
        }
        $wrapMarkerArray['###PRODUCT_LINK_DETAIL###'] = explode('|', $this->pi_list_linkSingle('|', $product->getUid(), TRUE, $linkArray, FALSE, $this->conf['overridePid']));
        $articleTemplate = $this->cObj->getSubpart($template, '###' . strtoupper($articleSubpart) . '###');
        if ($this->conf['useStockHandling'] == 1) {
            $product = Tx_Commerce_Utility_GeneralUtility::removeNoStockArticles($product, $this->conf['articles.']['showWithNoStock']);
        }
        // Set RenderMaxArticles to TS value
        if (!empty($localTs['maxArticles']) && (int) $localTs['maxArticles'] > 0) {
            $product->setRenderMaxArticles((int) $localTs['maxArticles']);
        }
        $subpartArray = array();
        if ($this->conf['disableArticleViewForProductlist'] == 1 && !$this->piVars['showUid'] || $this->conf['disableArticleView'] == 1) {
            $subpartArray['###' . strtoupper($articleSubpart) . '###'] = '';
        } else {
            $subpartArray['###' . strtoupper($articleSubpart) . '###'] = $this->makeArticleView('list', array(), $product, $articleMarker, $articleTemplate);
        }
        /**
         * Get The Checapest Price
         */
        $cheapestArticleUid = $product->getCheapestArticle();
        /**
         * Cheapest Article
         *
         * @var Tx_Commerce_Domain_Model_Article $cheapestArticle
         */
        $cheapestArticle = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Article', $cheapestArticleUid);
        $cheapestArticle->loadData();
        $cheapestArticle->loadPrices();
        $markerArray['###PRODUCT_CHEAPEST_PRICE_GROSS###'] = Tx_Commerce_ViewHelpers_Money::format($cheapestArticle->getPriceGross(), $this->currency);
        $cheapestArticleUid = $product->getCheapestArticle(1);
        /**
         * Cheapest Article
         *
         * @var Tx_Commerce_Domain_Model_Article $cheapestArticle
         */
        $cheapestArticle = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Article', $cheapestArticleUid);
        $cheapestArticle->loadData();
        $cheapestArticle->loadPrices();
        $markerArray['###PRODUCT_CHEAPEST_PRICE_NET###'] = Tx_Commerce_ViewHelpers_Money::format($cheapestArticle->getPriceNet(), $this->currency);
        foreach ($hookObjectsArr as $hookObj) {
            if (method_exists($hookObj, 'additionalMarkerProduct')) {
                $markerArray = $hookObj->additionalMarkerProduct($markerArray, $product, $this);
            }
        }
        foreach ($hookObjectsArr as $hookObj) {
            if (method_exists($hookObj, 'additionalSubpartsProduct')) {
                $subpartArray = $hookObj->additionalSubpartsProduct($subpartArray, $product, $this);
            }
        }
        $content = $this->substituteMarkerArrayNoCached($template, $markerArray, $subpartArray, $wrapMarkerArray);
        if ($typoscript['editPanel'] == 1) {
            $content = $this->cObj->editPanel($content, $typoscript['editPanel.'], 'Tx_Commerce_Domain_Model_Products:' . $product->getUid());
        }
        foreach ($hookObjectsArr as $hookObj) {
            if (method_exists($hookObj, 'ModifyContentProduct')) {
                $content = $hookObj->ModifyContentProduct($content, $product, $this);
            }
        }
        return $content;
    }