/** * Recursively replace simple tokens and insert tags * @param string $strText * @param array $arrTokens Array of Tokens * @param int $intTextFlags Filters the tokens and the text for a given set of options * * @return string */ public static function recursiveReplaceTokensAndTags($strText, $arrTokens, $intTextFlags = 0) { if ($intTextFlags > 0) { $arrTokens = static::convertToText($arrTokens, $intTextFlags); } // Must decode, tokens could be encoded $strText = \String::decodeEntities($strText); // Replace all opening and closing tags with a hash so they don't get stripped // by parseSimpleTokens() - this is useful e.g. for XML content $strHash = md5($strText); $strTagOpenReplacement = 'NC-TAG-OPEN-' . $strHash; $strTagCloseReplacement = 'NC-TAG-CLOSE-' . $strHash; $arrOriginal = array('<', '>'); $arrReplacement = array($strTagOpenReplacement, $strTagCloseReplacement); $strText = str_replace($arrOriginal, $arrReplacement, $strText); // first parse the tokens as they might have if-else clauses $strBuffer = \String::parseSimpleTokens($strText, $arrTokens); $strBuffer = str_replace($arrReplacement, $arrOriginal, $strBuffer); // then replace the insert tags $strBuffer = \Haste\Haste::getInstance()->call('replaceInsertTags', array($strBuffer, false)); // check if the inserttags have returned a simple token or an insert tag to parse if ((strpos($strBuffer, '##') !== false || strpos($strBuffer, '{{') !== false) && $strBuffer != $strText) { $strBuffer = static::recursiveReplaceTokensAndTags($strBuffer, $arrTokens, $intTextFlags); } $strBuffer = \String::restoreBasicEntities($strBuffer); if ($intTextFlags > 0) { $strBuffer = static::convertToText($strBuffer, $intTextFlags); } return $strBuffer; }
/** * Check permissions for that entry * @return void */ public static function check() { $session = \Session::getInstance()->getData(); if (\Input::get('act') == 'delete' && in_array(\Input::get('id'), static::getUndeletableIds())) { \System::log('Product type ID ' . \Input::get('id') . ' is used in an order and can\'t be deleted', __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } elseif (\Input::get('act') == 'deleteAll' && is_array($session['CURRENT']['IDS'])) { $arrDeletable = array_diff($session['CURRENT']['IDS'], static::getUndeletableIds()); if (count($arrDeletable) != count($session['CURRENT']['IDS'])) { $session['CURRENT']['IDS'] = array_values($arrDeletable); \Session::getInstance()->setData($session); \Message::addInfo($GLOBALS['TL_LANG']['MSC']['undeletableRecords']); } } // Disable variants if no such attributes are available \Haste\Haste::getInstance()->call('loadDataContainer', 'tl_iso_product'); $blnVariants = false; foreach ($GLOBALS['TL_DCA']['tl_iso_product']['fields'] as $strName => $arrConfig) { $objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strName]; if (null !== $objAttribute && $objAttribute->isVariantOption()) { $blnVariants = true; break; } } if (!$blnVariants) { \System::loadLanguageFile('explain'); unset($GLOBALS['TL_DCA']['tl_iso_producttype']['subpalettes']['variants']); $GLOBALS['TL_DCA']['tl_iso_producttype']['fields']['variants']['input_field_callback'] = function ($dc) { // Make sure variants are disabled in this product type (see #1114) \Database::getInstance()->prepare("UPDATE " . $dc->table . " SET variants='' WHERE id=?")->execute($dc->id); return '<br><p class="tl_info">' . $GLOBALS['TL_LANG']['XPL']['noVariantAttributes'] . '</p>'; }; } }
public function run($blnInstalled) { if ($blnInstalled) { Haste::getInstance()->call('loadDataContainer', 'tl_iso_product'); $arrFields = array(); foreach ($GLOBALS['TL_DCA']['tl_iso_product']['fields'] as $field => $config) { if ($config['inputType'] == 'mediaManager') { $arrFields[] = $field; } } if (empty($arrFields)) { return; } $objProducts = \Database::getInstance()->query("\n SELECT * FROM tl_iso_product WHERE language=''\n "); while ($objProducts->next()) { foreach ($arrFields as $field) { $arrUpdate = array(); $arrData = deserialize($objProducts->{$field}); if (!empty($arrData) && is_array($arrData)) { foreach ($arrData as $k => $image) { if ($image['translate'] == '') { $arrData[$k]['translate'] = 'none'; } } $arrUpdate[$field] = serialize($arrData); } } if (!empty($arrUpdate)) { \Database::getInstance()->prepare("UPDATE tl_iso_product %s WHERE id=?")->set($arrUpdate)->execute($objProducts->id); } } } }
/** * Fill the object's arrProducts array * @param array|null * @return array */ protected function findProducts($arrCacheIds = null) { $t = Product::getTable(); $arrColumns = array(); $arrCategories = $this->findCategories(); $arrProductIds = \Database::getInstance()->query("SELECT pid FROM " . ProductCategory::getTable() . " WHERE page_id IN (" . implode(',', $arrCategories) . ")")->fetchEach('pid'); $arrTypes = \Database::getInstance()->query("SELECT id FROM " . ProductType::getTable() . " WHERE variants='1'")->fetchEach('id'); if (empty($arrProductIds)) { return array(); } list($arrFilters, $arrSorting, $strWhere, $arrValues) = $this->getFiltersAndSorting(); if (!is_array($arrValues)) { $arrValues = array(); } $arrColumns[] = "(\n ({$t}.id IN (" . implode(',', $arrProductIds) . ") AND {$t}.type NOT IN (" . implode(',', $arrTypes) . "))\n OR {$t}.pid IN (" . implode(',', $arrProductIds) . ")\n )"; if (!empty($arrCacheIds) && is_array($arrCacheIds)) { $arrColumns[] = Product::getTable() . ".id IN (" . implode(',', $arrCacheIds) . ")"; } // Apply new/old product filter if ($this->iso_newFilter == 'show_new') { $arrColumns[] = Product::getTable() . ".dateAdded>=" . Isotope::getConfig()->getNewProductLimit(); } elseif ($this->iso_newFilter == 'show_old') { $arrColumns[] = Product::getTable() . ".dateAdded<" . Isotope::getConfig()->getNewProductLimit(); } if ($this->iso_list_where != '') { $arrColumns[] = Haste::getInstance()->call('replaceInsertTags', $this->iso_list_where); } if ($strWhere != '') { $arrColumns[] = $strWhere; } $objProducts = Product::findAvailableBy($arrColumns, $arrValues, array('order' => 'c.sorting', 'filters' => $arrFilters, 'sorting' => $arrSorting)); return null === $objProducts ? array() : $objProducts->getModels(); }
/** * Recursively replace simple tokens and insert tags * * @param string $strText * @param array $arrTokens Array of Tokens * * @return string */ public static function recursiveReplaceTokensAndTags($text, $tokens) { // Must decode, tokens could be encoded $text = \String::decodeEntities($text); // Replace all opening and closing tags with a hash so they don't get stripped // by parseSimpleTokens() $hash = md5($text); $openTagReplacement = 'LEADS-TAG-OPEN-' . $hash; $closeTagReplacement = 'LEADS-TAG-CLOSE-' . $hash; $original = array('<', '>'); $replacement = array($openTagReplacement, $closeTagReplacement); $text = str_replace($original, $replacement, $text); // first parse the tokens as they might have if-else clauses $buffer = \String::parseSimpleTokens($text, $tokens); // Restore tags $buffer = str_replace($replacement, $original, $buffer); // Replace the Insert Tags $buffer = \Haste\Haste::getInstance()->call('replaceInsertTags', array($buffer, false)); // Check if the Insert Tags have returned a Simple Token or an Insert Tag to parse if ((strpos($buffer, '##') !== false || strpos($buffer, '{{') !== false) && $buffer != $text) { $buffer = static::recursiveReplaceTokensAndTags($buffer, $tokens); } $buffer = \String::restoreBasicEntities($buffer); return $buffer; }
public function __construct(\Database\Result $objResult = null) { parent::__construct($objResult); if (!is_array($GLOBALS['ISO_ADR'])) { Haste::getInstance()->call('loadDataContainer', static::$strTable); \System::loadLanguageFile('addresses'); } }
/** * Generate the order details view when editing an order * @param object * @param string * @return string */ public function generateOrderDetails($dc) { $objOrder = \Database::getInstance()->execute("SELECT * FROM tl_iso_product_collection WHERE id=" . $dc->id); if (!$objOrder->numRows) { \Controller::redirect('contao/main.php?act=error'); } $GLOBALS['TL_CSS'][] = \Haste\Util\Debug::uncompressedFile('system/modules/isotope/assets/css/print.min.css|print'); // Generate a regular order details module \Input::setGet('uid', $objOrder->uniqid); $objModule = new \Isotope\Module\OrderDetails(\Database::getInstance()->execute("SELECT * FROM tl_module WHERE type='iso_orderdetails'")); return Haste::getInstance()->call('replaceInsertTags', $objModule->generate(true)); }
/** * Generate the order details view when editing an order * * @param object $dc * * @return string */ public function generateOrderDetails($dc) { $objOrder = Order::findByPk($dc->id); if ($objOrder === null) { return ''; } $GLOBALS['TL_CSS'][] = Debug::uncompressedFile('system/modules/isotope/assets/css/print.min.css|print'); // Try to find a order details module or create a dummy FE module model if (($objModuleModel = \ModuleModel::findOneBy('type', 'iso_orderdetails')) === null) { $objModuleModel = new \ModuleModel(); $objModuleModel->type = 'iso_orderdetails'; $objModuleModel->iso_collectionTpl = 'iso_collection_default'; } // Generate a regular order details module \Input::setGet('uid', $objOrder->uniqid); $objModule = new OrderDetails($objModuleModel); return Haste::getInstance()->call('replaceInsertTags', $objModule->generate(true)); }
/** * Load libraries and scripts * * @param \ModuleModel $objModule * @param string $strColumn */ public function __construct($objModule, $strColumn = 'main') { parent::__construct($objModule, $strColumn); if ($this->iso_list_where != '') { $this->iso_list_where = Haste::getInstance()->call('replaceInsertTags', $this->iso_list_where); } $this->iso_buttons = deserialize($this->iso_buttons); if (!is_array($this->iso_buttons)) { $this->iso_buttons = array(); } Isotope::initialize(); // Load Isotope JavaScript and style sheet if (TL_MODE == 'FE') { $version = RepositoryVersion::encode(Isotope::VERSION); $GLOBALS['TL_JAVASCRIPT'][] = Debug::uncompressedFile('system/modules/isotope/assets/js/isotope.min.js|static|' . $version); $GLOBALS['TL_CSS'][] = Debug::uncompressedFile('system/modules/isotope/assets/css/isotope.min.css|screen|static|' . $version); // Disable caching for pages with certain modules (eg. Cart) if ($this->blnDisableCache) { global $objPage; $objPage->cache = 0; } } }
/** * Generate unique order ID including the order prefix * * @return string */ protected function generateUniqueId() { if ($this->arrData['uniqid'] != '') { return $this->arrData['uniqid']; } $objConfig = $this->getRelated('config_id'); if (null === $objConfig) { $objConfig = Isotope::getConfig(); } return uniqid(Haste::getInstance()->call('replaceInsertTags', array((string) $objConfig->orderPrefix, false)), true); }
/** * Return list of fields that must be inherited by variants * @return array */ public static function getInheritFields() { static $arrFields; Haste::getInstance()->call('loadDataContainer', 'tl_iso_product'); if (null === $arrFields) { $arrFields = array(); $arrDCA =& $GLOBALS['TL_DCA']['tl_iso_product']['fields']; foreach ($arrDCA as $field => $config) { if ($config['attributes']['inherit']) { $arrFields[] = $field; } } } return $arrFields; }
/** * Generate the next higher Document Number based on existing records * * @param string $strPrefix * @param int $intDigits * * @return string */ protected function generateDocumentNumber($strPrefix, $intDigits) { if ($this->arrData['document_number'] != '') { return $this->arrData['document_number']; } // !HOOK: generate a custom order ID if (isset($GLOBALS['ISO_HOOKS']['generateDocumentNumber']) && is_array($GLOBALS['ISO_HOOKS']['generateDocumentNumber'])) { foreach ($GLOBALS['ISO_HOOKS']['generateDocumentNumber'] as $callback) { $objCallback = \System::importStatic($callback[0]); $strOrderId = $objCallback->{$callback}[1]($this, $strPrefix, $intDigits); if ($strOrderId !== false) { $this->arrData['document_number'] = $strOrderId; break; } } } if ($this->arrData['document_number'] == '') { $strPrefix = Haste::getInstance()->call('replaceInsertTags', array($strPrefix, false)); $intPrefix = utf8_strlen($strPrefix); // Lock tables so no other order can get the same ID \Database::getInstance()->lockTables(array(static::$strTable => 'WRITE')); try { // Retrieve the highest available order ID $objMax = \Database::getInstance()->prepare("\n SELECT document_number\n FROM " . static::$strTable . "\n WHERE\n type=?\n " . ($strPrefix != '' ? " AND document_number LIKE '{$strPrefix}%'" : '') . "\n AND store_id=?\n ORDER BY CAST(" . ($strPrefix != '' ? "SUBSTRING(document_number, " . ($intPrefix + 1) . ")" : 'document_number') . " AS UNSIGNED) DESC\n ")->limit(1)->execute(array_search(get_called_class(), static::getModelTypes()), $this->store_id); $intMax = (int) substr($objMax->document_number, $intPrefix); $this->arrData['document_number'] = $strPrefix . str_pad($intMax + 1, $intDigits, '0', STR_PAD_LEFT); \Database::getInstance()->prepare("\n UPDATE " . static::$strTable . " SET document_number=? WHERE id=?\n ")->execute($this->arrData['document_number'], $this->id); \Database::getInstance()->unlockTables(); } catch (\Exception $e) { // Make sure tables are always unlocked \Database::getInstance()->unlockTables(); throw $e; } } return $this->arrData['document_number']; }
public function testInstance() { $this->assertInstanceOf('\\Haste\\Haste', Haste::getInstance()); }
/** * Generate and return document template * @return string */ protected function generateTemplate(IsotopeProductCollection $objCollection, array $arrTokens) { $objTemplate = new \Isotope\Template($this->documentTpl); $objTemplate->setData($this->arrData); $objTemplate->title = \String::parseSimpleTokens($this->documentTitle, $arrTokens); $objTemplate->collection = $objCollection; // Render the collection $objCollectionTemplate = new \Isotope\Template($this->collectionTpl); $objCollection->addToTemplate($objCollectionTemplate, array('gallery' => $this->gallery, 'sorting' => $objCollection->getItemsSortingCallable($this->orderCollectionBy))); $objTemplate->products = $objCollectionTemplate->parse(); // Generate template and fix PDF issues, see Contao's ModuleArticle $strBuffer = Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), false)); $strBuffer = html_entity_decode($strBuffer, ENT_QUOTES, $GLOBALS['TL_CONFIG']['characterSet']); $strBuffer = \Controller::convertRelativeUrls($strBuffer, '', true); // Remove form elements and JavaScript links $arrSearch = array('@<form.*</form>@Us', '@<a [^>]*href="[^"]*javascript:[^>]+>.*</a>@Us'); $strBuffer = preg_replace($arrSearch, '', $strBuffer); // URL decode image paths (see contao/core#6411) // Make image paths absolute $strBuffer = preg_replace_callback('@(src=")([^"]+)(")@', function ($args) { if (preg_match('@^(http://|https://)@', $args[2])) { return $args[2]; } return $args[1] . TL_ROOT . '/' . rawurldecode($args[2]) . $args[3]; }, $strBuffer); // Handle line breaks in preformatted text $strBuffer = preg_replace_callback('@(<pre.*</pre>)@Us', 'nl2br_callback', $strBuffer); // Default PDF export using TCPDF $arrSearch = array('@<span style="text-decoration: ?underline;?">(.*)</span>@Us', '@(<img[^>]+>)@', '@(<div[^>]+block[^>]+>)@', '@[\\n\\r\\t]+@', '@<br( /)?><div class="mod_article@', '@href="([^"]+)(pdf=[0-9]*(&|&)?)([^"]*)"@'); $arrReplace = array('<u>$1</u>', '<br>$1', '<br>$1', ' ', '<div class="mod_article', 'href="$1$4"'); $strBuffer = preg_replace($arrSearch, $arrReplace, $strBuffer); return $strBuffer; }
/** * Generate a filter form */ protected function generateFilters() { $this->Template->hasFilters = false; if (is_array($this->iso_filterFields) && count($this->iso_filterFields)) { $time = time(); $arrFilters = array(); $arrInput = \Input::post('filter'); $arrCategories = $this->findCategories(); foreach ($this->iso_filterFields as $strField) { $arrValues = array(); $objValues = \Database::getInstance()->execute("\n SELECT DISTINCT p1.{$strField} FROM tl_iso_product p1\n LEFT OUTER JOIN tl_iso_product p2 ON p1.pid=p2.id\n WHERE\n p1.language=''\n " . (BE_USER_LOGGED_IN === true ? '' : "AND p1.published='1' AND (p1.start='' OR p1.start<{$time}) AND (p1.stop='' OR p1.stop>{$time}) ") . "\n AND (\n p1.id IN (\n SELECT pid FROM " . \Isotope\Model\ProductCategory::getTable() . " WHERE page_id IN (" . implode(',', $arrCategories) . ")\n )\n OR p1.pid IN (\n SELECT pid FROM " . \Isotope\Model\ProductCategory::getTable() . " WHERE page_id IN (" . implode(',', $arrCategories) . ")\n )\n )\n " . (BE_USER_LOGGED_IN === true ? '' : " AND (p1.pid=0 OR (p2.published='1' AND (p2.start='' OR p2.start<{$time}) AND (p2.stop='' OR p2.stop>{$time})))") . "\n " . ($this->iso_list_where == '' ? '' : " AND " . Haste::getInstance()->call('replaceInsertTags', $this->iso_list_where))); while ($objValues->next()) { $arrValues[] = deserialize($objValues->{$strField}, false); } if ($this->blnUpdateCache && in_array($arrInput[$strField], $arrValues)) { Isotope::getRequestCache()->setFilterForModule($strField, Filter::attribute($strField)->isEqualTo($arrInput[$strField]), $this->id); } elseif ($this->blnUpdateCache && $arrInput[$strField] == '') { Isotope::getRequestCache()->removeFilterForModule($strField, $this->id); } elseif (($objFilter = Isotope::getRequestCache()->getFilterForModule($strField, $this->id)) !== null && $objFilter->valueNotIn($arrValues)) { // Request cache contains wrong value, delete it! $this->blnUpdateCache = true; Isotope::getRequestCache()->removeFilterForModule($strField, $this->id); RequestCache::deleteById(\Input::get('isorc')); } elseif (!$this->blnUpdateCache) { // Only generate options if we do not reload anyway if (empty($arrValues)) { continue; } $arrData = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strField]; if (is_array($GLOBALS['ISO_ATTR'][$arrData['inputType']]['callback']) && !empty($GLOBALS['ISO_ATTR'][$arrData['inputType']]['callback'])) { foreach ($GLOBALS['ISO_ATTR'][$arrData['inputType']]['callback'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrData = $objCallback->{$callback[1]}($strField, $arrData, $this); } } // Use the default routine to initialize options data $arrWidget = \Widget::getAttributesFromDca($arrData, $strField); $objFilter = Isotope::getRequestCache()->getFilterForModule($strField, $this->id); if (($objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strField]) !== null && $objAttribute instanceof IsotopeAttributeWithOptions) { $objAttribute->optionsSource = 'attribute'; $arrWidget['options'] = $objAttribute->getOptionsForProductFilter($arrValues); } foreach ($arrValues as $value) { $arrWidget['options'][] = array('value' => $value, 'label' => $value == '' ? ' ' : 'text'); } // Must have options to apply the filter if (!is_array($arrWidget['options'])) { continue; } foreach ($arrWidget['options'] as $k => $option) { if ($option['value'] == '') { $arrWidget['blankOptionLabel'] = $option['label']; unset($arrWidget['options'][$k]); continue; } elseif (!in_array($option['value'], $arrValues) || $option['value'] == '-') { // @deprecated IsotopeAttributeWithOptions::getOptionsForProductFilter already checks this unset($arrWidget['options'][$k]); continue; } $arrWidget['options'][$k]['default'] = null !== $objFilter && $objFilter->valueEquals($option['value']) ? '1' : ''; } // Hide fields with just one option (if enabled) if ($this->iso_filterHideSingle && count($arrWidget['options']) < 2) { continue; } $arrFilters[$strField] = $arrWidget; } } // !HOOK: alter the filters if (isset($GLOBALS['ISO_HOOKS']['generateFilters']) && is_array($GLOBALS['ISO_HOOKS']['generateFilters'])) { foreach ($GLOBALS['ISO_HOOKS']['generateFilters'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrFilters = $objCallback->{$callback}[1]($arrFilters); } } if (!empty($arrFilters)) { $this->Template->hasFilters = true; $this->Template->filterOptions = $arrFilters; } } }
/** * Find all products we need to list. * @param array|null * @return array */ protected function findProducts($arrCacheIds = null) { $arrColumns = array(); $arrCategories = $this->findCategories(); list($arrFilters, $arrSorting, $strWhere, $arrValues) = $this->getFiltersAndSorting(); if (!is_array($arrValues)) { $arrValues = array(); } $arrColumns[] = "c.page_id IN (" . implode(',', $arrCategories) . ")"; if (!empty($arrCacheIds) && is_array($arrCacheIds)) { $arrColumns[] = Product::getTable() . ".id IN (" . implode(',', $arrCacheIds) . ")"; } // Apply new/old product filter if ($this->iso_newFilter == 'show_new') { $arrColumns[] = Product::getTable() . ".dateAdded>=" . Isotope::getConfig()->getNewProductLimit(); } elseif ($this->iso_newFilter == 'show_old') { $arrColumns[] = Product::getTable() . ".dateAdded<" . Isotope::getConfig()->getNewProductLimit(); } if ($this->iso_list_where != '') { $arrColumns[] = Haste::getInstance()->call('replaceInsertTags', $this->iso_list_where); } if ($strWhere != '') { $arrColumns[] = $strWhere; } $objProducts = Product::findAvailableBy($arrColumns, $arrValues, array('order' => 'c.sorting', 'filters' => $arrFilters, 'sorting' => $arrSorting)); return null === $objProducts ? array() : $objProducts->getModels(); }
/** * Make sure at least one variant attribute is enabled * @param mixed * @return mixed * @throws UnderflowException */ public function validateVariantAttributes($varValue) { \Haste\Haste::getInstance()->call('loadDataContainer', 'tl_iso_product'); $blnError = true; $arrAttributes = deserialize($varValue); $arrVariantAttributeLabels = array(); if (!empty($arrAttributes) && is_array($arrAttributes)) { foreach ($arrAttributes as $arrAttribute) { $objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$arrAttribute['name']]; if (null !== $objAttribute && $objAttribute->isVariantOption()) { $arrVariantAttributeLabels[] = $objAttribute->name; if ($arrAttribute['enabled']) { $blnError = false; } } } } if ($blnError) { \System::loadLanguageFile('explain'); throw new \UnderflowException(sprintf($GLOBALS['TL_LANG']['tl_iso_producttype']['noVariantAttributes'], implode(', ', $arrVariantAttributeLabels))); } return $varValue; }
/** * Retrieve the array of notification data for parsing simple tokens * @param int * @return array */ public function getNotificationTokens($intNotification) { $arrTokens = deserialize($this->email_data, true); $arrTokens['uniqid'] = $this->uniqid; $arrTokens['order_status_id'] = $this->order_status; $arrTokens['order_status'] = $this->getStatusLabel(); $arrTokens['recipient_email'] = $this->getEmailRecipient(); $arrTokens['order_id'] = $this->id; $arrTokens['order_items'] = $this->sumItemsQuantity(); $arrTokens['order_products'] = $this->countItems(); $arrTokens['order_subtotal'] = Isotope::formatPriceWithCurrency($this->getSubtotal(), false); $arrTokens['order_total'] = Isotope::formatPriceWithCurrency($this->getTotal(), false); $arrTokens['document_number'] = $this->document_number; $arrTokens['cart_html'] = ''; $arrTokens['cart_text'] = ''; $arrTokens['document'] = ''; // Add billing/customer address fields if (($objAddress = $this->getBillingAddress()) !== null) { foreach ($objAddress->row() as $k => $v) { $arrTokens['billing_address_' . $k] = Format::dcaValue($objAddress->getTable(), $k, $v); // @deprecated (use ##billing_address_*##) $arrTokens['billing_' . $k] = $arrTokens['billing_address_' . $k]; } $arrTokens['billing_address'] = $objAddress->generate($this->getRelated('config_id')->getBillingFieldsConfig()); // @deprecated (use ##billing_address##) $arrTokens['billing_address_text'] = $arrTokens['billing_address']; } // Add shipping address fields if (($objAddress = $this->getShippingAddress()) !== null) { foreach ($objAddress->row() as $k => $v) { $arrTokens['shipping_address_' . $k] = Format::dcaValue($objAddress->getTable(), $k, $v); // @deprecated (use ##billing_address_*##) $arrTokens['shipping_' . $k] = $arrTokens['shipping_address_' . $k]; } $arrTokens['shipping_address'] = $objAddress->generate($this->getRelated('config_id')->getShippingFieldsConfig()); // Shipping address equals billing address // @deprecated (use ##shipping_address##) if ($objAddress->id == $this->getBillingAddress()->id) { $arrTokens['shipping_address_text'] = $this->requiresPayment() ? $GLOBALS['TL_LANG']['MSC']['useBillingAddress'] : $GLOBALS['TL_LANG']['MSC']['useCustomerAddress']; } else { $arrTokens['shipping_address_text'] = $arrTokens['shipping_address']; } } // Add payment method info if ($this->hasPayment() && ($objPayment = $this->getPaymentMethod()) !== null) { $arrTokens['payment_id'] = $objPayment->id; $arrTokens['payment_label'] = $objPayment->getLabel(); $arrTokens['payment_note'] = $objPayment->note; } // Add shipping method info if ($this->hasShipping() && ($objShipping = $this->getShippingMethod()) !== null) { $arrTokens['shipping_id'] = $objShipping->id; $arrTokens['shipping_label'] = $objShipping->getLabel(); $arrTokens['shipping_note'] = $objShipping->note; } // Add config fields if ($this->getRelated('config_id') !== null) { foreach ($this->getRelated('config_id')->row() as $k => $v) { $arrTokens['config_' . $k] = Format::dcaValue($this->getRelated('config_id')->getTable(), $k, $v); } } // Add member fields if ($this->member > 0 && $this->getRelated('member') !== null) { foreach ($this->getRelated('member')->row() as $k => $v) { $arrTokens['member_' . $k] = Format::dcaValue($this->getRelated('member')->getTable(), $k, $v); } } if ($intNotification > 0 && ($objNotification = Notification::findByPk($intNotification)) !== null) { $objTemplate = new \Isotope\Template($objNotification->iso_collectionTpl); $objTemplate->isNotification = true; $this->addToTemplate($objTemplate, array('gallery' => $objNotification->iso_gallery, 'sorting' => $this->getItemsSortingCallable($objNotification->iso_orderCollectionBy))); $arrTokens['cart_html'] = Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), false)); $objTemplate->textOnly = true; $arrTokens['cart_text'] = strip_tags(Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), true))); // Generate and "attach" document /** @var \Isotope\Interfaces\IsotopeDocument $objDocument */ if ($objNotification->iso_document > 0 && ($objDocument = Document::findByPk($objNotification->iso_document)) !== null) { $strFilePath = $objDocument->outputToFile($this, TL_ROOT . '/system/tmp'); $arrTokens['document'] = str_replace(TL_ROOT . '/', '', $strFilePath); } } // !HOOK: add custom email tokens if (isset($GLOBALS['ISO_HOOKS']['getOrderNotificationTokens']) && is_array($GLOBALS['ISO_HOOKS']['getOrderNotificationTokens'])) { foreach ($GLOBALS['ISO_HOOKS']['getOrderNotificationTokens'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrTokens = $objCallback->{$callback}[1]($this, $arrTokens); } } return $arrTokens; }
/** * Format product configuration using \Haste\Data * * @param array $arrConfig * @param IsotopeProduct|Product $objProduct * * @return array */ public static function formatProductConfiguration(array $arrConfig, IsotopeProduct $objProduct) { Product::setActive($objProduct); $strTable = $objProduct->getTable(); foreach ($arrConfig as $k => $v) { /** @type \Isotope\Model\Attribute $objAttribute */ if (($objAttribute = $GLOBALS['TL_DCA'][$strTable]['attributes'][$k]) !== null && $objAttribute instanceof IsotopeAttributeWithOptions) { /** @type \Widget $strClass */ $strClass = $objAttribute->getFrontendWidget(); $arrField = $strClass::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$k], $k, $v, $k, $strTable, $objProduct); $arrOptions = array(); $values = $v; if (!empty($arrField['options']) && is_array($arrField['options'])) { if (!is_array($values)) { $values = array($values); } $arrOptions = array_filter($arrField['options'], function (&$option) use(&$values) { if (($pos = array_search($option['value'], $values)) !== false) { $option = $option['label']; unset($values[$pos]); return true; } return false; }); if (!empty($values)) { $arrOptions = array_merge($arrOptions, $values); } } $formatted = implode(', ', $arrOptions); } else { $formatted = Format::dcaValue($strTable, $k, $v); } $arrConfig[$k] = new Plain($v, Format::dcaLabel($strTable, $k), array('formatted' => Haste::getInstance()->call('replaceInsertTags', array($formatted)))); } Product::unsetActive(); return $arrConfig; }
/** * Format options label and value * * @param array $arrData * @param string $strTable * @param bool $blnSkipEmpty * * @return array */ public static function formatOptions(array $arrData, $strTable = 'tl_iso_product', $blnSkipEmpty = true) { $arrOptions = array(); foreach ($arrData as $field => $value) { if ($blnSkipEmpty && ($value == '' || $value == '-')) { continue; } $arrOptions[$field] = array('label' => Format::dcaLabel($strTable, $field), 'value' => Haste::getInstance()->call('replaceInsertTags', Format::dcaValue($strTable, $field, $value))); } return $arrOptions; }
public static function getCleanTokens($intProductType, Order $objOrder, $objNotification, $arrTokens = array()) { $objTemplate = new Template($objNotification->iso_collectionTpl); $objTemplate->isNotification = true; // FIX - call to custom function since addToTemplate isn't static static::addToTemplate($intProductType, $objOrder, $objTemplate, array('gallery' => $objNotification->iso_gallery, 'sorting' => $objOrder->getItemsSortingCallable($objNotification->iso_orderCollectionBy))); $arrTokens['cart_html'] = Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), false)); $objTemplate->textOnly = true; $arrTokens['cart_text'] = strip_tags(Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), true))); return $arrTokens; }
/** * Find all products we need to list. * @return array */ protected function findProducts($arrCacheIds = null) { $arrColumns = array(); $arrCategories = $this->findCategories(); //Get filters and sorting values list($arrValues, $strWhere, $strSorting) = $this->getFiltersAndSorting(); //Handle no values if (!is_array($arrValues)) { $arrValues = array(); } //Add categories to query $arrColumns[] = Product_Model::getTable() . ".id IN( SELECT pid FROM tl_iso_product_category WHERE page_id IN (" . implode(',', $arrCategories) . "))"; //Get only cache IDs if (!empty($arrCacheIds) && is_array($arrCacheIds)) { $arrColumns[] = Product_Model::getTable() . ".id IN (" . implode(',', $arrCacheIds) . ")"; } // Apply new/old product filter if ($this->iso_newFilter == 'show_new') { $arrColumns[] = Product_Model::getTable() . ".dateAdded>=" . Isotope::getConfig()->getNewProductLimit(); } elseif ($this->iso_newFilter == 'show_old') { $arrColumns[] = Product_Model::getTable() . ".dateAdded<" . Isotope::getConfig()->getNewProductLimit(); } if ($this->iso_list_where != '') { $arrColumns[] = Haste::getInstance()->call('replaceInsertTags', $this->iso_list_where); } //Add where query from filters/sorting if ($strWhere != '') { $arrColumns[] = $strWhere; } //Calculate the total on the query $intTotal = static::countPublishedBy($arrColumns, $arrValues); //Generate pagination and get offset $offset = $this->generatePagination($intTotal); //Build options $arrOptions = array('offset' => $offset, 'limit' => $this->numberOfItems && $this->perPage ? min($this->numberOfItems, $this->perPage) : ($this->perPage ?: $this->numberOfItems), 'order' => $strSorting); // Temporary fix for category sorting values $arrColumns[] = "c.page_id IN (" . implode(',', $arrCategories) . ")"; //Run query $objProducts = Product_Model::findPublishedBy($arrColumns, $arrValues, $arrOptions); return null === $objProducts ? array() : $objProducts->getModels(); }
/** * Initialize a new collection and duplicate everything from the source * @param IsotopeProductCollection */ public static function createFromCollection(IsotopeProductCollection $objSource) { global $objPage; $objCollection = new static(); $objConfig = $objSource->getRelated('config_id'); if (null === $objConfig) { $objConfig = Isotope::getConfig(); } $objCollection->uniqid = uniqid(Haste::getInstance()->call('replaceInsertTags', array((string) $objConfig->orderPrefix, false)), true); $objCollection->source_collection_id = (int) $objSource->id; $objCollection->config_id = (int) $objConfig->id; $objCollection->store_id = (int) $objSource->store_id; $objCollection->member = (int) $objSource->member; $objCollection->language = (string) $GLOBALS['TL_LANGUAGE']; $objCollection->currency = (string) $objConfig->currency; $objCollection->pageId = (int) $objPage->id; $objCollection->setShippingMethod($objSource->getShippingMethod()); $objCollection->setPaymentMethod($objSource->getPaymentMethod()); $objCollection->setShippingAddress($objSource->getShippingAddress()); $objCollection->setBillingAddress($objSource->getBillingAddress()); $arrItemIds = $objCollection->copyItemsFrom($objSource); $arrSurchargeIds = $objCollection->copySurchargesFrom($objSource, $arrItemIds); $objCollection->updateDatabase(); // HOOK: order status has been updated if (isset($GLOBALS['ISO_HOOKS']['createFromProductCollection']) && is_array($GLOBALS['ISO_HOOKS']['createFromProductCollection'])) { foreach ($GLOBALS['ISO_HOOKS']['createFromProductCollection'] as $callback) { $objCallback = \System::importStatic($callback[0]); $objCallback->{$callback}[1]($objCollection, $objSource, $arrItemIds, $arrSurchargeIds); } } return $objCollection; }
/** * Generate ajax */ public function generateAjax() { if (!\Environment::get('isAjaxRequest')) { return; } // todo: Use the current filters too... if ($this->iso_searchAutocomplete && \Input::get('iso_autocomplete') == $this->id) { include_once TL_ROOT . '/system/modules/isotope_direct/config/stopwords.php'; $arrWhere = array("c.page_id IN (" . implode(',', array_map('intval', $this->findCategories())) . ")"); $arrValues = array(); $keywords = explode(' ', \Input::get('query')); for ($i = 0; $i < count($keywords); $i++) { $strTerm = trim($keywords[$i]); if (empty($strTerm) || in_array(strtolower($strTerm), array_map('strtolower', $GLOBALS['KEYWORD_STOP_WORDS'])) || in_array(strtolower($strTerm), array_map('strtolower', $GLOBALS['KEYWORD_STOP_WORDS']))) { continue; } $arrWhere[] = Product_Model::getTable() . "." . $this->iso_searchAutocomplete . " REGEXP ?"; $arrValues[] = $strTerm; } if ($this->iso_list_where != '') { $arrWhere[] = Haste::getInstance()->call('replaceInsertTags', $this->iso_list_where); } $objProducts = Product_Model::findPublishedBy($arrWhere, $arrValues, array('order' => "c.sorting")); if (null === $objProducts) { $objResponse = new JsonResponse(array('suggestions' => array())); $objResponse->send(); } $objResponse = new JsonResponse(array('suggestions' => array_values(array_map('html_entity_decode', $objProducts->fetchEach($this->iso_searchAutocomplete))))); $objResponse->send(); } }