/** * 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>', \CommerceTeam\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']; }
/** * 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 */ $hooks = HookFactory::getHooks('Controller/AddressesController', 'getAddresses'); foreach ($hooks as $hook) { if (method_exists($hook, 'editSelectStatement')) { $select = $hook->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']] = \CommerceTeam\Commerce\Utility\GeneralUtility::removeXSSStripTagsArray($address); } return $result; }
/** * Fetch billing, delivery and payment from session. * * @return void */ protected function fetchSessionDataIntoSessionAttribute() { $feUser = $this->getFrontendUser(); $this->sessionData['billing'] = \CommerceTeam\Commerce\Utility\GeneralUtility::removeXSSStripTagsArray($feUser->getKey('ses', \CommerceTeam\Commerce\Utility\GeneralUtility::generateSessionKey('billing'))); $this->sessionData['delivery'] = \CommerceTeam\Commerce\Utility\GeneralUtility::removeXSSStripTagsArray($feUser->getKey('ses', \CommerceTeam\Commerce\Utility\GeneralUtility::generateSessionKey('delivery'))); $this->sessionData['payment'] = \CommerceTeam\Commerce\Utility\GeneralUtility::removeXSSStripTagsArray($feUser->getKey('ses', \CommerceTeam\Commerce\Utility\GeneralUtility::generateSessionKey('payment'))); $this->sessionData['mails'] = $feUser->getKey('ses', \CommerceTeam\Commerce\Utility\GeneralUtility::generateSessionKey('mails')); if ($this->piVars['check'] == 'billing' && $this->piVars['step'] == 'payment') { // Remove reference to delivery address $this->sessionData['delivery'] = false; $feUser->setKey('ses', \CommerceTeam\Commerce\Utility\GeneralUtility::generateSessionKey('delivery'), false); } }
/** * 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>', \CommerceTeam\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>', \CommerceTeam\Commerce\Utility\GeneralUtility::removeXSSStripTagsArray($acAfter)) . '</th>'; } if ($addTr) { $result .= '</tr>'; } $colCount += count($acBefore) + count($acAfter); return $result; }