/**
     * Create a matrix of producible articles
     *
     * @param array $parameter Parameter
     * @param FormEngine $fObj Form engine
     *
     * @return string A HTML-table with checkboxes and all needed stuff
     */
    public function producibleArticles(array $parameter, FormEngine $fObj)
    {
        $this->uid = (int) $parameter['row']['uid'];
        $this->pid = (int) $parameter['row']['pid'];
        // get existing articles for this product, if they where not fetched yet
        if ($this->existingArticles == NULL) {
            $this->existingArticles = $this->belib->getArticlesOfProduct($this->uid);
        }
        // get all attributes for this product, if they where not fetched yet
        if ($this->attributes == NULL) {
            $this->attributes = $this->belib->getAttributesForProduct($this->uid, TRUE, TRUE, TRUE);
        }
        $rowCount = $this->calculateRowCount();
        if ($rowCount > 1000) {
            return sprintf($fObj->sL('LLL:EXT:commerce/Resources/Private/Language/locallang_db.xml:tx_commerce_products.to_many_articles'), $rowCount);
        }
        // create the headrow from the product attributes, select attributes without
        // valuelist and normal select attributes
        $colCount = 0;
        $headRow = $this->getHeadRow($colCount, array(' '));
        $valueMatrix = (array) $this->getValues();
        $counter = 0;
        $resultRows = '';
        $resultRows .= $fObj->sL('LLL:EXT:commerce/Resources/Private/Language/locallang_db.xml:tx_commerce_products.create_warning');
        $this->getRows($valueMatrix, $resultRows, $counter, $headRow);
        $emptyRow = '<tr><td><input type="checkbox" name="createList[empty]" /></td>';
        $emptyRow .= '<td colspan="' . ($colCount - 1) . '">' . $fObj->sL('LLL:EXT:commerce/Resources/Private/Language/locallang_db.xml:tx_commerce_products.empty_article') . '</td></tr>';
        // create a checkbox for selecting all articles
        $selectJs = '<script language="JavaScript">
			function updateArticleList() {
				var sourceSB = document.getElementById("selectAllArticles");
				for (var i = 1; i <= ' . $rowCount . '; i++) {
					document.getElementById("createRow_" +i).checked = sourceSB.checked;
				}
			}
		</script>';
        $selectAllRow = '';
        if (count($valueMatrix) > 0) {
            $selectAllRow = '<tr><td><input type="checkbox" id="selectAllArticles" onclick="updateArticleList()" /></td>';
            $selectAllRow .= '<td colspan="' . ($colCount - 1) . '">' . $fObj->sL('LLL:EXT:commerce/Resources/Private/Language/locallang_db.xml:tx_commerce_products.select_all_articles') . '</td></tr>';
        }
        $result = '<table border="0">' . $selectJs . $headRow . $emptyRow . $selectAllRow . $resultRows . '</table>';
        return $result;
    }
Esempio n. 2
0
    /**
     * Localize attributes of product
     *
     * @param int $productUid Product uid
     * @param int $localizedProductUid Localized product uid
     * @param int $value Value
     *
     * @return void
     */
    protected function translateAttributesOfProduct($productUid, $localizedProductUid, $value)
    {
        $database = $this->getDatabaseConnection();
        // get all related attributes
        $productAttributes = $this->belib->getAttributesForProduct($productUid, FALSE, TRUE);
        // check if localized product has attributes
        $localizedProductAttributes = $this->belib->getAttributesForProduct($localizedProductUid);
        // Check product has attrinutes and no attributes are
        // avaliable for localized version
        if ($localizedProductAttributes == FALSE && count($productAttributes)) {
            // if true
            $langIsoCode = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('sys_language', (int) $value, 'static_lang_isocode');
            $langIdent = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('static_languages', (int) $langIsoCode['static_lang_isocode'], 'lg_typo3');
            $langIdent = strtoupper($langIdent['lg_typo3']);
            foreach ($productAttributes as $productAttribute) {
                // only if we have attributes type 4 and no valuelist
                if ($productAttribute['uid_correlationtype'] == 4 && !$productAttribute['has_valuelist'] == 1) {
                    $localizedProductAttribute = $productAttribute;
                    unset($localizedProductAttribute['attributeData']);
                    unset($localizedProductAttribute['has_valuelist']);
                    /**
                     * Decide on what to to on lokalisation, how to act
                     *
                     * @see translateAttributesOfProduct($productUid, $localizedProductUid, $value)
                     * attributeLokalisationType[0|1|2]
                     * 0: set blank
                     * 1: Copy
                     * 2: prepend [Translate to . $langRec['title'] . :]
                     */
                    if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][COMMERCE_EXTKEY]['extConf']['attributeLokalisationType']) && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][COMMERCE_EXTKEY]['extConf']['attributeLokalisationType']) {
                        \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('
							extension configuration parameter
							attributeLokalisationType
							is deprecated since commerce 1.0.0, it will be removed in commerce 1.4.0, please use instead
							attributeLocalizationType
						');
                        $extConf =& $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][COMMERCE_EXTKEY]['extConf'];
                        $extConf['attributeLocalizationType'] = $extConf['attributeLokalisationType'];
                    }
                    switch ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][COMMERCE_EXTKEY]['extConf']['attributeLocalizationType']) {
                        case self::ATTRIBUTE_LOCALIZATION_TITLE_EMPTY:
                            unset($localizedProductAttribute['default_value']);
                            break;
                        case self::ATTRIBUTE_LOCALIZATION_TITLE_COPY:
                            break;
                        case self::ATTRIBUTE_LOCALIZATION_TITLE_PREPENDED:
                            /**
                             * Walk through the array and prepend text
                             */
                            $prepend = '[Translate to ' . $langIdent . ':] ';
                            $localizedProductAttribute['default_value'] = $prepend . $localizedProductAttribute['default_value'];
                            break;
                        default:
                    }
                    $localizedProductAttribute['uid_local'] = $localizedProductUid;
                    $database->exec_INSERTquery('tx_commerce_products_attributes_mm', $localizedProductAttribute);
                }
            }
            /**
             * Update the flexform
             */
            $resProduct = $database->exec_SELECTquery('attributesedit,attributes', 'tx_commerce_products', 'uid =' . $productUid);
            if ($rowProduct = $database->sql_fetch_assoc($resProduct)) {
                $product['attributesedit'] = $this->belib->buildLocalisedAttributeValues($rowProduct['attributesedit'], $langIdent);
                $database->exec_UPDATEquery('tx_commerce_products', 'uid = ' . $localizedProductUid, $product);
            }
        }
    }