/** * 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(); }
/** * Fill the object's arrProducts array * * @param array|null $arrCacheIds * * @return array */ protected function findProducts($arrCacheIds = null) { $t = Product::getTable(); $arrColumns = array(); $arrCategories = $this->findCategories(); $arrProductIds = \Database::getInstance()->query("\n SELECT pid\n FROM tl_iso_product_category\n WHERE page_id IN (" . implode(',', $arrCategories) . ")\n ")->fetchEach('pid'); $arrTypes = \Database::getInstance()->query("SELECT id FROM tl_iso_producttype WHERE variants='1'")->fetchEach('id'); if (empty($arrProductIds)) { return array(); } $queryBuilder = new FilterQueryBuilder(Isotope::getRequestCache()->getFiltersForModules($this->iso_filterModules)); $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[] = $this->iso_list_where; } if ($queryBuilder->hasSqlCondition()) { $arrColumns[] = $queryBuilder->getSqlWhere(); } $arrSorting = Isotope::getRequestCache()->getSortingsForModules($this->iso_filterModules); if (empty($arrSorting) && $this->iso_listingSortField != '') { $direction = $this->iso_listingSortDirection == 'DESC' ? Sort::descending() : Sort::ascending(); $arrSorting[$this->iso_listingSortField] = $direction; } $objProducts = Product::findAvailableBy($arrColumns, $queryBuilder->getSqlValues(), array('order' => 'c.sorting', 'filters' => $queryBuilder->getFilters(), 'sorting' => $arrSorting)); return null === $objProducts ? array() : $objProducts->getModels(); }
/** * Find all available property types and return as array * @param array * @return array */ public static function findAllAvailable(&$arrCategories) { $strHash = md5(implode(',', $arrCategories)); if (!\Cache::has(static::$strKey . '-' . $strHash)) { $t = Product::getTable(); $arrAvailable = array(); if (!is_array($arrCategories) || empty($arrCategories)) { $arrCategories = array(0); } //This query is by far the fastest way to get the available attributes $strQuery = "SELECT {$t}." . static::$strKey . " FROM {$t} WHERE " . static::$strKey . " != '' AND {$t}.id IN (" . implode(',', static::getProductsForCategories($arrCategories)) . ")"; if (BE_USER_LOGGED_IN !== true) { $time = time(); $strQuery .= " AND {$t}.published='1' AND ({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time})"; } $objResult = \Database::getInstance()->execute($strQuery); if ($objResult->numRows) { while ($objResult->next()) { if (strlen($objResult->{static::$strKey}) && !in_array($objResult->{static::$strKey}, $arrAvailable)) { $arrAvailable[specialchars($objResult->{static::$strKey})] = $objResult->{static::$strKey}; } } } ksort($arrAvailable); \Cache::set(static::$strKey . '-' . $strHash, $arrAvailable); } return \Cache::get(static::$strKey . '-' . $strHash); }
/** * Check if a product can be deleted by the current backend user * Deleting is prohibited if a product has been ordered * @return bool */ public static function getUndeletableIds() { static $arrProducts; if (null === $arrProducts) { $arrProducts = \Database::getInstance()->query("\n SELECT p.type AS type FROM " . Product::getTable() . " p\n INNER JOIN " . ProductCollectionItem::getTable() . " i ON i.product_id=p.id\n INNER JOIN " . ProductCollection::getTable() . " c ON i.pid=c.id\n WHERE p.type>0 AND c.type='order'\n UNION\n SELECT p.type AS type FROM " . Product::getTable() . " p\n INNER JOIN " . Product::getTable() . " p2 ON p2.pid=p.pid\n INNER JOIN " . ProductCollectionItem::getTable() . " i ON i.product_id=p2.id\n INNER JOIN " . ProductCollection::getTable() . " c ON i.pid=c.id\n WHERE c.type='order'\n ")->fetchEach('type'); } return $arrProducts; }
/** * List the products * @param array * @return string */ public function listRows($row) { $objProduct = Product::findByPk($row['pid']); $label = $objProduct->name; if ($objProduct->sku != '') { $label .= ' <span style="color:#b3b3b3; padding-left:3px;">[' . $objProduct->sku . ']</span>'; } return $label; }
/** * Generate query string for native filters * * @param array $arrFilters * * @return array */ public static function buildSqlFilters(array $arrFilters) { $strWhere = ''; $arrWhere = array(); $arrValues = array(); $arrGroups = array(); // Initiate native SQL filtering /** @var \Isotope\RequestCache\Filter $objFilter */ foreach ($arrFilters as $k => $objFilter) { if ($objFilter->hasGroup() && $arrGroups[$objFilter->getGroup()] !== false) { if ($objFilter->isDynamicAttribute()) { $arrGroups[$objFilter->getGroup()] = false; } else { $arrGroups[$objFilter->getGroup()][] = $k; } } elseif (!$objFilter->hasGroup() && !$objFilter->isDynamicAttribute()) { $arrWhere[] = $objFilter->sqlWhere(); $arrValues[] = $objFilter->sqlValue(); unset($arrFilters[$k]); } } if (!empty($arrGroups)) { foreach ($arrGroups as $arrGroup) { $arrGroupWhere = array(); // Skip dynamic attributes if (false === $arrGroup) { continue; } foreach ($arrGroup as $k) { $objFilter = $arrFilters[$k]; $arrGroupWhere[] = $objFilter->sqlWhere(); $arrValues[] = $objFilter->sqlValue(); unset($arrFilters[$k]); } $arrWhere[] = '(' . implode(' OR ', $arrGroupWhere) . ')'; } } if (!empty($arrWhere)) { $time = time(); $t = Product::getTable(); $strTemp = ""; $arrTemp = $arrWhere; if (in_array("tl_iso_product.shipping_exempt = ?", $arrTemp)) { $strTemp = 'tl_iso_product.shipping_exempt = ? AND '; unset($arrTemp[array_search('tl_iso_product.shipping_exempt = ?', $arrTemp)]); } $strTemp .= "(" . implode(' OR ', $arrTemp) . ")"; $strWhere = "\n (\n (" . $strTemp . ")\n OR {$t}.id IN (SELECT {$t}.pid FROM tl_iso_product AS {$t} WHERE {$t}.language='' AND " . implode(' AND ', $arrWhere) . (BE_USER_LOGGED_IN === true ? '' : " AND {$t}.published='1' AND ({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time})") . ")\n OR {$t}.pid IN (SELECT {$t}.id FROM tl_iso_product AS {$t} WHERE {$t}.language='' AND " . implode(' AND ', $arrWhere) . (BE_USER_LOGGED_IN === true ? '' : " AND {$t}.published='1' AND ({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time})") . ")\n )\n "; $arrValues = array_merge($arrValues, $arrValues, $arrValues); } return array($arrFilters, $strWhere, $arrValues); }
/** * Restore categories when restoring a product * * @param int $intId * @param string $strTable * @param array $arrData * @param int $intVersion */ public function restoreVersion($intId, $strTable, $arrData, $intVersion) { if ($strTable != Product::getTable()) { return; } $arrData = SubtableVersion::find(ProductCategory::getTable(), $intId, $intVersion); if (null !== $arrData) { \Database::getInstance()->query("DELETE FROM " . ProductCategory::getTable() . " WHERE pid={$intId}"); foreach ($arrData as $arrRow) { \Database::getInstance()->prepare("INSERT INTO " . ProductCategory::getTable() . " %s")->set($arrRow)->execute(); } } }
/** * Generate a product label and return it as HTML string * @param array * @param string * @param object * @param array * @return string */ public function generate($row, $label, $dc, $args) { $objProduct = Product::findByPk($row['id']); foreach ($GLOBALS['TL_DCA'][$dc->table]['list']['label']['fields'] as $i => $field) { switch ($field) { // Add an image case 'images': $arrImages = deserialize($objProduct->images); $args[$i] = ' '; if (is_array($arrImages) && !empty($arrImages)) { foreach ($arrImages as $image) { $strImage = 'isotope/' . strtolower(substr($image['src'], 0, 1)) . '/' . $image['src']; if (!is_file(TL_ROOT . '/' . $strImage)) { continue; } $size = @getimagesize(TL_ROOT . '/' . $strImage); $args[$i] = sprintf('<a href="%s" onclick="Backend.openModalImage({\'width\':%s,\'title\':\'%s\',\'url\':\'%s\'});return false"><img src="%s" alt="%s" align="left"></a>', $strImage, $size[0], str_replace("'", "\\'", $objProduct->name), $strImage, \Image::get($strImage, 50, 50, 'proportional'), $image['alt']); break; } } break; case 'name': $args[$i] = $objProduct->name; /** @var \Isotope\Model\ProductType $objProductType */ if ($row['pid'] == 0 && ($objProductType = ProductType::findByPk($row['type'])) !== null && $objProductType->hasVariants()) { // Add a variants link $args[$i] = sprintf('<a href="%s" title="%s">%s</a>', ampersand(\Environment::get('request')) . '&id=' . $row['id'], specialchars($GLOBALS['TL_LANG'][$dc->table]['showVariants']), $args[$i]); } break; case 'price': $objPrice = ProductPrice::findPrimaryByProductId($row['id']); if (null !== $objPrice) { /** @var \Isotope\Model\TaxClass $objTax */ $objTax = $objPrice->getRelated('tax_class'); $strTax = null === $objTax ? '' : ' (' . $objTax->getName() . ')'; $args[$i] = $objPrice->getValueForTier(1) . $strTax; } break; case 'variantFields': $attributes = array(); foreach ($GLOBALS['TL_DCA'][$dc->table]['list']['label']['variantFields'] as $variantField) { $attributes[] = '<strong>' . Format::dcaLabel($dc->table, $variantField) . ':</strong> ' . Format::dcaValue($dc->table, $variantField, $objProduct->{$variantField}); } $args[$i] = ($args[$i] ? $args[$i] . '<br>' : '') . implode(', ', $attributes); break; } } return $args; }
/** * Generate ajax */ public function generateAjax() { if (!\Environment::get('isAjaxRequest')) { return; } if ($this->iso_searchAutocomplete && \Input::get('iso_autocomplete') == $this->id) { $objProducts = Product::findPublishedByCategories($this->findCategories(), array('order' => 'c.sorting')); if (null === $objProducts) { $objResponse = new JsonResponse(array()); $objResponse->send(); } $objResponse = new JsonResponse(array_values($objProducts->fetchEach($this->iso_searchAutocomplete))); $objResponse->send(); } }
/** * Return list of default and widget legends * @param Widget * @return array */ public function getLegends($objWidget) { $this->loadDataContainer(\Isotope\Model\Attribute::getTable()); \System::loadLanguageFile(\Isotope\Model\Product::getTable()); $arrLegends = $GLOBALS['TL_DCA'][\Isotope\Model\Attribute::getTable()]['fields']['legend']['options']; $arrLegends = array_intersect_key($GLOBALS['TL_LANG'][\Isotope\Model\Product::getTable()], array_flip($arrLegends)); $varValue = $objWidget->value; if (!empty($varValue) && is_array($varValue)) { foreach ($varValue as $arrField) { if ($arrField['legend'] != '' && !isset($arrLegends[$arrField['legend']])) { $arrLegends[$arrField['legend']] = $arrField['legend']; } } } return $arrLegends; }
/** * Handle the paste button callback for tl_iso_product * @param DataContainer * @param array * @param string * @param bool * @param array * @return string * @link http://www.contao.org/callbacks.html#paste_button_callback */ public function generate(\DataContainer $dc, $row, $table, $cr, $arrClipboard = false) { // Disable all buttons if there is a circular reference if ($arrClipboard !== false && ($arrClipboard['mode'] == 'cut' && ($cr == 1 || $arrClipboard['id'] == $row['id']) || $arrClipboard['mode'] == 'cutAll' && ($cr == 1 || in_array($row['id'], $arrClipboard['id'])))) { return ''; } $objProduct = \Database::getInstance()->prepare("SELECT p.*, t.variants FROM " . \Isotope\Model\Product::getTable() . " p LEFT JOIN " . ProductType::getTable() . " t ON p.type=t.id WHERE p.id=?")->execute($arrClipboard['id']); // Copy or cut a single product or variant if ($arrClipboard['mode'] == 'cut' || $arrClipboard['mode'] == 'copy') { return $this->pasteVariant($objProduct, $table, $row, $arrClipboard); } elseif ($arrClipboard['mode'] == 'cutAll' || $arrClipboard['mode'] == 'copyAll') { return $this->pasteAll($objProduct, $table, $row, $arrClipboard); } $this->Session->set('CLIPBOARD', null); throw new \InvalidArgumentException('Unhandled paste_button_callback mode "' . $arrClipboard['mode'] . '"'); }
/** * Restore pricing information when restoring a product * @param int * @param string * @param array * @param int */ public function restoreVersion($intId, $strTable, $arrData, $intVersion) { if ($strTable != Product::getTable()) { return; } $arrData = SubtableVersion::find(ProductPrice::getTable(), $intId, $intVersion); if (null !== $arrData) { \Database::getInstance()->query("DELETE FROM tl_iso_product_pricetier WHERE pid IN (SELECT id FROM " . ProductPrice::getTable() . " WHERE pid={$intId})"); \Database::getInstance()->query("DELETE FROM " . ProductPrice::getTable() . " WHERE pid={$intId}"); foreach ($arrData['prices'] as $arrRow) { \Database::getInstance()->prepare("INSERT INTO " . ProductPrice::getTable() . " %s")->set($arrRow)->execute(); } foreach ($arrData['tiers'] as $arrRow) { \Database::getInstance()->prepare("INSERT INTO tl_iso_product_pricetier %s")->set($arrRow)->execute(); } } }
/** * HTML form for checkout * @param IsotopeProductCollection The order being places * @param Module The checkout module instance * @return mixed */ public function checkoutForm(IsotopeProductCollection $objOrder, \Module $objModule) { $i = 0; $arrData = array('aid' => $this->payone_aid, 'portalid' => $this->payone_portalid, 'mode' => $this->debug ? 'test' : 'live', 'request' => $this->trans_type == 'auth' ? 'preauthorization' : 'authorization', 'encoding' => 'UTF-8', 'clearingtype' => $this->payone_clearingtype, 'reference' => $objOrder->id, 'display_name' => 'no', 'display_address' => 'no', 'successurl' => \Environment::get('base') . $objModule->generateUrlForStep('complete', $objOrder), 'backurl' => \Environment::get('base') . $objModule->generateUrlForStep('failed'), 'amount' => $objOrder->getTotal() * 100, 'currency' => $objOrder->currency, 'param' => 'paymentMethodPayone' . $this->id); foreach ($objOrder->getItems() as $objItem) { // Set the active product for insert tags replacement if ($objItem->hasProduct()) { Product::setActive($objItem->getProduct()); } $strOptions = ''; $arrOptions = Isotope::formatOptions($objItem->getOptions()); Product::unsetActive(); if (!empty($arrOptions)) { array_walk($arrOptions, function (&$option) { $option = $option['label'] . ': ' . $option['value']; }); $strOptions = ' (' . implode(', ', $arrOptions) . ')'; } $arrData['id[' . ++$i . ']'] = $objItem->getSku(); $arrData['pr[' . $i . ']'] = round($objItem->getPrice(), 2) * 100; $arrData['no[' . $i . ']'] = $objItem->quantity; $arrData['de[' . $i . ']'] = specialchars($objItem->getName() . $strOptions); } foreach ($objOrder->getSurcharges() as $k => $objSurcharge) { if (!$objSurcharge->addToTotal) { continue; } $arrData['id[' . ++$i . ']'] = 'surcharge' . $k; $arrData['pr[' . $i . ']'] = $objSurcharge->total_price * 100; $arrData['no[' . $i . ']'] = '1'; $arrData['de[' . $i . ']'] = $objSurcharge->label; } ksort($arrData); // Do not urlencode values because Payone does not properly decode POST values (whatever...) $strHash = md5(implode('', $arrData) . $this->payone_key); $objTemplate = new \Isotope\Template('iso_payment_payone'); $objTemplate->id = $this->id; $objTemplate->data = $arrData; $objTemplate->hash = $strHash; $objTemplate->billing_address = $objOrder->getBillingAddress()->row(); $objTemplate->headline = $GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][0]; $objTemplate->message = $GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][1]; $objTemplate->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][2]); return $objTemplate->parse(); }
/** * Find all products we need to list. * @param array|null * @return array */ protected function findProducts($arrCacheIds = null) { $arrIds = array(0); $objProduct = Product::findAvailableByIdOrAlias(Input::getAutoItem('product')); if (null === $objProduct) { return array(); } $objRelated = RelatedProduct::findByProductAndCategories($objProduct, $this->iso_related_categories); if (null !== $objRelated) { while ($objRelated->next()) { $ids = trimsplit(',', $objRelated->products); if (!empty($ids) && is_array($ids)) { $arrIds = array_unique(array_merge($arrIds, $ids)); } } } $objProducts = Product::findAvailableByIds($arrIds, array('order' => \Database::getInstance()->findInSet(Product::getTable() . '.id', $arrIds))); return null === $objProducts ? array() : $objProducts->getModels(); }
/** * Generate header fields for product or variant * @param array * @param \Contao\DataContainer */ public function headerFields($arrFields, $dc) { $t = Product::getTable(); $arrNew = array(); $objProduct = Product::findByPk($dc->id); if (null === $objProduct) { return $arrFields; } $arrAttributes = array('name', 'alias', 'sku'); if ($objProduct->isVariant()) { $arrAttributes = array_merge($arrAttributes, array_intersect(array_merge($objProduct->getAttributes(), $objProduct->getVariantAttributes()), Attribute::getVariantOptionFields())); } foreach ($arrAttributes as $field) { $v = $objProduct->{$field}; if ($v != '') { $arrNew[Format::dcaLabel($t, $field)] = Format::dcaValue($t, $field, $v); } } // Add fields that have potentially been added through the DCA, but do not allow to override the core fields return array_merge($arrNew, array_diff_key($arrFields, $arrNew)); }
/** * Generate module * @return void */ protected function compile() { global $objPage; global $objIsotopeListPage; $objProduct = Product::findAvailableByIdOrAlias(\Haste\Input\Input::getAutoItem('product')); if (null === $objProduct) { $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); exit; } $arrConfig = array('module' => $this, 'template' => $this->iso_reader_layout ?: $objProduct->getRelated('type')->reader_template, 'gallery' => $this->iso_gallery ?: $objProduct->getRelated('type')->reader_gallery, 'buttons' => deserialize($this->iso_buttons, true), 'useQuantity' => $this->iso_use_quantity, 'jumpTo' => $objIsotopeListPage ?: $objPage); if (\Environment::get('isAjaxRequest') && \Input::post('AJAX_MODULE') == $this->id && \Input::post('AJAX_PRODUCT') == $objProduct->getProductId()) { $objResponse = new HtmlResponse($objProduct->generate($arrConfig)); $objResponse->send(); } $arrCSS = deserialize($objProduct->cssID, true); $this->Template->product = $objProduct->generate($arrConfig); $this->Template->product_id = $arrCSS[0] != '' ? ' id="' . $arrCSS[0] . '"' : ''; $this->Template->product_class = trim('product ' . ($objProduct->isNew() ? 'new ' : '') . $arrCSS[1]); $this->Template->referer = 'javascript:history.go(-1)'; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; $this->addMetaTags($objProduct); $this->addCanonicalProductUrls($objProduct); }
/** * Get the sorting labels (asc/desc) for an attribute * @param string * @return array */ protected static function getSortingLabels($field) { $arrData = $GLOBALS['TL_DCA'][Product::getTable()]['fields'][$field]; switch ($arrData['eval']['rgxp']) { case 'price': case 'digit': return array($GLOBALS['TL_LANG']['MSC']['low_to_high'], $GLOBALS['TL_LANG']['MSC']['high_to_low']); case 'date': case 'time': case 'datim': return array($GLOBALS['TL_LANG']['MSC']['old_to_new'], $GLOBALS['TL_LANG']['MSC']['new_to_old']); } // !HOOK: custom sorting labels if (isset($GLOBALS['ISO_HOOKS']['sortingLabels']) && is_array($GLOBALS['ISO_HOOKS']['sortingLabels'])) { foreach ($GLOBALS['ISO_HOOKS']['sortingLabels'] as $callback) { $objCallback = \System::importStatic($callback[0]); $varReturn = $objCallback->{$callback}[1]($field, $arrData, null); if ($varReturn !== false) { return $varReturn; } } } return array($GLOBALS['TL_LANG']['MSC']['a_to_z'], $GLOBALS['TL_LANG']['MSC']['z_to_a']); }
/** * Get WHERE statement for SQL filter * @return string */ public function sqlWhere() { if ($this->isMultilingualAttribute()) { $strWhere = 'IFNULL(translation.' . $this->arrConfig['attribute'] . ', ' . Product::getTable() . '.' . $this->arrConfig['attribute'] . ')'; } else { $strWhere = Product::getTable() . '.' . $this->arrConfig['attribute']; } $strWhere .= ' ' . $this->getOperatorForSQL() . ' ?'; return $strWhere; }
$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['email_recipient_bcc'] =& $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['recipients']; /** * Models */ $GLOBALS['TL_MODELS'][\Isotope\Model\Address::getTable()] = 'Isotope\\Model\\Address'; $GLOBALS['TL_MODELS'][\Isotope\Model\Attribute::getTable()] = 'Isotope\\Model\\Attribute'; $GLOBALS['TL_MODELS'][\Isotope\Model\BasePrice::getTable()] = 'Isotope\\Model\\BasePrice'; $GLOBALS['TL_MODELS'][\Isotope\Model\Config::getTable()] = 'Isotope\\Model\\Config'; $GLOBALS['TL_MODELS'][\Isotope\Model\Document::getTable()] = 'Isotope\\Model\\Document'; $GLOBALS['TL_MODELS'][\Isotope\Model\Download::getTable()] = 'Isotope\\Model\\Download'; $GLOBALS['TL_MODELS'][\Isotope\Model\Gallery::getTable()] = 'Isotope\\Model\\Gallery'; $GLOBALS['TL_MODELS'][\Isotope\Model\Group::getTable()] = 'Isotope\\Model\\Group'; $GLOBALS['TL_MODELS'][\Isotope\Model\Label::getTable()] = 'Isotope\\Model\\Label'; $GLOBALS['TL_MODELS'][\Isotope\Model\OrderStatus::getTable()] = 'Isotope\\Model\\OrderStatus'; $GLOBALS['TL_MODELS'][\Isotope\Model\Payment::getTable()] = 'Isotope\\Model\\Payment'; $GLOBALS['TL_MODELS'][\Isotope\Model\Product::getTable()] = 'Isotope\\Model\\Product'; $GLOBALS['TL_MODELS'][\Isotope\Model\ProductCategory::getTable()] = 'Isotope\\Model\\ProductCategory'; $GLOBALS['TL_MODELS'][\Isotope\Model\ProductCollection::getTable()] = 'Isotope\\Model\\ProductCollection'; $GLOBALS['TL_MODELS'][\Isotope\Model\ProductCollectionDownload::getTable()] = 'Isotope\\Model\\ProductCollectionDownload'; $GLOBALS['TL_MODELS'][\Isotope\Model\ProductCollectionItem::getTable()] = 'Isotope\\Model\\ProductCollectionItem'; $GLOBALS['TL_MODELS'][\Isotope\Model\ProductCollectionSurcharge::getTable()] = 'Isotope\\Model\\ProductCollectionSurcharge'; $GLOBALS['TL_MODELS'][\Isotope\Model\ProductPrice::getTable()] = 'Isotope\\Model\\ProductPrice'; $GLOBALS['TL_MODELS'][\Isotope\Model\ProductCache::getTable()] = 'Isotope\\Model\\ProductCache'; $GLOBALS['TL_MODELS'][\Isotope\Model\ProductType::getTable()] = 'Isotope\\Model\\ProductType'; $GLOBALS['TL_MODELS'][\Isotope\Model\RelatedCategory::getTable()] = 'Isotope\\Model\\RelatedCategory'; $GLOBALS['TL_MODELS'][\Isotope\Model\RelatedProduct::getTable()] = 'Isotope\\Model\\RelatedProduct'; $GLOBALS['TL_MODELS'][\Isotope\Model\RequestCache::getTable()] = 'Isotope\\Model\\RequestCache'; $GLOBALS['TL_MODELS'][\Isotope\Model\Shipping::getTable()] = 'Isotope\\Model\\Shipping'; $GLOBALS['TL_MODELS'][\Isotope\Model\TaxClass::getTable()] = 'Isotope\\Model\\TaxClass'; $GLOBALS['TL_MODELS'][\Isotope\Model\TaxRate::getTable()] = 'Isotope\\Model\\TaxRate'; /**
/** * Returns an array of all allowed product IDs and variant IDs for the current backend user * @return array|bool */ public static function getAllowedIds() { $objUser = \BackendUser::getInstance(); if ($objUser->isAdmin) { $arrProducts = true; } else { $arrNewRecords = $_SESSION['BE_DATA']['new_records']['tl_iso_product']; $arrProductTypes = $objUser->iso_product_types; $arrGroups = array(); // Return false if there are no product types if (!is_array($arrProductTypes) || empty($arrProductTypes)) { return false; } // Find the user groups if (is_array($objUser->iso_groups) && count($objUser->iso_groups) > 0) { $arrGroups = array_merge($arrGroups, $objUser->iso_groups, \Database::getInstance()->getChildRecords($objUser->iso_groups, Group::getTable())); if (in_array('rootPaste', $objUser->iso_groupp)) { $arrGroups[] = 0; } } $objProducts = \Database::getInstance()->execute("\n SELECT id FROM tl_iso_product\n WHERE pid=0\n AND language=''\n " . (empty($arrGroups) ? '' : "AND gid IN (" . implode(',', $arrGroups) . ")") . "\n AND (\n type IN (" . implode(',', $arrProductTypes) . ")" . (is_array($arrNewRecords) && !empty($arrNewRecords) ? " OR id IN (" . implode(',', $arrNewRecords) . ")" : '') . ")\n "); if ($objProducts->numRows == 0) { return array(); } $arrProducts = $objProducts->fetchEach('id'); $arrProducts = array_merge($arrProducts, \Database::getInstance()->getChildRecords($arrProducts, 'tl_iso_product')); } // HOOK: allow extensions to define allowed products if (isset($GLOBALS['ISO_HOOKS']['getAllowedProductIds']) && is_array($GLOBALS['ISO_HOOKS']['getAllowedProductIds'])) { foreach ($GLOBALS['ISO_HOOKS']['getAllowedProductIds'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrAllowed = $objCallback->{$callback}[1](); if ($arrAllowed === false) { return false; } elseif (is_array($arrAllowed)) { if ($arrProducts === true) { $arrProducts = $arrAllowed; } else { $arrProducts = array_intersect($arrProducts, $arrAllowed); } } } } // If all product are allowed, we don't need to filter if ($arrProducts === true || count($arrProducts) == Product::countAll()) { return true; } return $arrProducts; }
public function modifyDC(&$arrDca = null) { // get the product switch ($this->iso_direct_checkout_product_mode) { case 'product_type': if (($objTypes = FieldPaletteModel::findByPidAndTableAndField($this->objModule->id, 'tl_module', 'iso_direct_checkout_product_types')) !== null) { while ($objTypes->next()) { $arrColumns = array('type=?'); $arrValues = array($objTypes->iso_direct_checkout_product_type); if ($this->iso_listingSortField) { $arrSorting = array($this->iso_listingSortField => $this->iso_listingSortDirection == 'DESC' ? Sort::descending() : Sort::ascending()); } else { $arrSorting = array(); } $objProducts = Product::findPublishedBy($arrColumns, $arrValues, array('sorting' => $arrSorting)); if ($objProducts->count() > 0) { $objProduct = $objProducts->current(); $this->arrProducts[] = array('product' => $objProduct, 'useQuantity' => $objTypes->iso_use_quantity); $this->addProductFields($objProduct, $objTypes->iso_use_quantity, $objTypes->iso_addSubscriptionCheckbox, $arrDca); } } } break; default: if (($objProducts = FieldPaletteModel::findByPidAndTableAndField($this->objModule->id, 'tl_module', 'iso_direct_checkout_products')) !== null) { while ($objProducts->next()) { $objProduct = Product::findByPk($objProducts->iso_direct_checkout_product); $this->arrProducts[] = array('product' => $objProduct, 'useQuantity' => $objProducts->iso_use_quantity); $this->addProductFields($objProduct, $objProducts->iso_use_quantity, $objProducts->iso_addSubscriptionCheckbox, $arrDca); } } break; } // add address fields \Controller::loadDataContainer('tl_iso_address'); \System::loadLanguageFile('tl_iso_address'); $arrAddressFields = deserialize(Config::findByPk($this->iso_config_id)->address_fields, true); // add billing address fields foreach ($arrAddressFields as $strName => $arrAddressField) { $arrData = $GLOBALS['TL_DCA']['tl_iso_address']['fields'][$strName]; if (!is_array($arrData) || $arrAddressField['billing'] == 'disabled') { continue; } $arrData['eval']['mandatory'] = $arrAddressField['billing'] == 'mandatory'; $this->arrBillingAddressFields[] = $strName; $this->addEditableField($strName, $arrData); } if ($this->iso_use_notes) { $this->addEditableField('notes', array('label' => &$GLOBALS['TL_LANG']['MSC']['iso_note'], 'exclude' => true, 'inputType' => 'textarea', 'eval' => array('tl_class' => 'clr w50'), 'sql' => "text NULL")); } $this->addEditableField('shippingaddress', array('label' => array($GLOBALS['TL_LANG']['MSC']['differentShippingAddress'], $GLOBALS['TL_LANG']['MSC']['differentShippingAddress']), 'inputType' => 'checkbox', 'eval' => array('submitOnChange' => true))); // add shipping address fields $arrShippingAddressFields = array(); foreach ($arrAddressFields as $strName => $arrAddressField) { $arrData = $GLOBALS['TL_DCA']['tl_iso_address']['fields'][$strName]; if (!is_array($arrData) || $arrAddressField['shipping'] == 'disabled') { continue; } $arrData['eval']['mandatory'] = $arrAddressField['shipping'] == 'mandatory'; $this->addEditableField('shippingaddress_' . $strName, $arrData); $arrShippingAddressFields[] = 'shippingaddress_' . $strName; } $this->dca['palettes']['__selector__'][] = 'shippingaddress'; $this->dca['subpalettes']['shippingaddress'] = implode(',', $arrShippingAddressFields); $this->arrShippingAddressFields = $arrShippingAddressFields; }
protected function compile() { $periodFactory = new PeriodFactory(); $arrSession = \Session::getInstance()->get('iso_reports'); $strPeriod = (string) $arrSession[$this->name]['period']; $intColumns = (int) $arrSession[$this->name]['columns']; $blnVariants = (bool) $arrSession[$this->name]['variants']; $intStatus = (int) $arrSession[$this->name]['iso_status']; if ($arrSession[$this->name]['from'] == '') { $intStart = strtotime('-' . ($intColumns - 1) . ' ' . $strPeriod); } else { $intStart = (int) $arrSession[$this->name]['from']; } $period = $periodFactory->create($strPeriod); $intStart = $period->getPeriodStart($intStart); $dateFrom = $period->getKey($intStart); $dateTo = $period->getKey(strtotime('+ ' . ($intColumns - 1) . ' ' . $strPeriod, $intStart)); $arrData = array('rows' => array()); $arrData['header'] = $this->getHeader($period, $intStart, $intColumns); $groupVariants = $blnVariants ? 'p1.id' : 'IF(p1.pid=0, p1.id, p1.pid)'; $objProducts = \Database::getInstance()->query("\n SELECT\n IFNULL({$groupVariants}, i.product_id) AS product_id,\n IFNULL(p1.name, i.name) AS variant_name,\n IFNULL(p2.name, i.name) AS product_name,\n p1.sku AS product_sku,\n p2.sku AS variant_sku,\n IF(p1.pid=0, p1.type, p2.type) AS type,\n i.configuration AS product_configuration,\n SUM(i.quantity) AS quantity,\n SUM(i.tax_free_price * i.quantity) AS total,\n " . $period->getSqlField($this->strDateField) . " AS dateGroup\n FROM " . ProductCollectionItem::getTable() . " i\n LEFT JOIN " . ProductCollection::getTable() . " o ON i.pid=o.id\n LEFT JOIN " . OrderStatus::getTable() . " os ON os.id=o.order_status\n LEFT OUTER JOIN " . Product::getTable() . " p1 ON i.product_id=p1.id\n LEFT OUTER JOIN " . Product::getTable() . " p2 ON p1.pid=p2.id\n WHERE o.type='order' AND o.order_status>0 AND o.locked!=''\n " . ($intStatus > 0 ? " AND o.order_status=" . $intStatus : '') . "\n " . $this->getProductProcedure('p1') . "\n " . $this->getConfigProcedure('o', 'config_id') . "\n GROUP BY dateGroup, product_id\n HAVING dateGroup>={$dateFrom} AND dateGroup<={$dateTo}\n "); // Cache product types so call to findByPk() will trigger the registry ProductType::findMultipleByIds($objProducts->fetchEach('type')); $arrRaw = array(); $objProducts->reset(); // Prepare product data while ($objProducts->next()) { $arrAttributes = array(); $arrVariantAttributes = array(); $blnHasVariants = false; // Can't use it without a type if ($objProducts->type > 0 && ($objType = ProductType::findByPk($objProducts->type)) !== null) { /** @type ProductType $objType */ $arrAttributes = $objType->getAttributes(); $arrVariantAttributes = $objType->getVariantAttributes(); $blnHasVariants = $objType->hasVariants(); $product_type_name = $objType->name; } $arrOptions = array('name' => $objProducts->variant_name); // Use product title if name is not a variant attribute if ($blnHasVariants && !in_array('name', $arrVariantAttributes)) { $arrOptions['name'] = $objProducts->product_name; } $strSku = $blnHasVariants ? $objProducts->variant_sku : $objProducts->product_sku; if (in_array('sku', $arrAttributes) && $strSku != '') { $arrOptions['name'] = sprintf('%s <span style="color:#b3b3b3; padding-left:3px;">[%s]</span>', $arrOptions['name'], $strSku); } if ($blnVariants && $blnHasVariants) { if (in_array('sku', $arrVariantAttributes) && $objProducts->product_sku != '') { $arrOptions['name'] = sprintf('%s <span style="color:#b3b3b3; padding-left:3px;">[%s]</span>', $arrOptions['name'], $objProducts->product_sku); } foreach (deserialize($objProducts->product_configuration, true) as $strName => $strValue) { if (isset($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strName])) { $strValue = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strName]['options'][$strValue] ? $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strName]['options'][$strValue] : $strValue; $strName = $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strName]['label'][0] ? $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$strName]['label'][0] : $strName; } $arrOptions[] = '<span class="variant">' . $strName . ': ' . $strValue . '</span>'; } } $arrOptions['name'] = '<span class="product">' . $arrOptions['name'] . '</span>'; $arrRaw[$objProducts->product_id]['name'] = implode('<br>', $arrOptions); $arrRaw[$objProducts->product_id]['product_type_name'] = $product_type_name; $arrRaw[$objProducts->product_id][$objProducts->dateGroup] = (double) $arrRaw[$objProducts->product_id][$objProducts->dateGroup] + (double) $objProducts->total; $arrRaw[$objProducts->product_id][$objProducts->dateGroup . '_quantity'] = (int) $arrRaw[$objProducts->product_id][$objProducts->dateGroup . '_quantity'] + (int) $objProducts->quantity; $arrRaw[$objProducts->product_id]['total'] = (double) $arrRaw[$objProducts->product_id]['total'] + (double) $objProducts->total; $arrRaw[$objProducts->product_id]['quantity'] = (int) $arrRaw[$objProducts->product_id]['quantity'] + (int) $objProducts->quantity; } // Prepare columns $arrColumns = array(); for ($i = 0; $i < $intColumns; $i++) { $arrColumns[] = $period->getKey($intStart); $intStart = $period->getNext($intStart); } $arrFooter = array(); // Sort the data if ($arrSession[$this->name]['tl_sort'] == 'product_name') { usort($arrRaw, function ($a, $b) { return strcasecmp($a['name'], $b['name']); }); } else { usort($arrRaw, function ($a, $b) { return $a['total'] == $b['total'] ? 0 : ($a['total'] < $b['total'] ? 1 : -1); }); } // Generate data foreach ($arrRaw as $arrProduct) { $arrRow = array(array('value' => array($arrProduct['name'], sprintf('<span style="color:#b3b3b3;">[%s]</span>', $arrProduct['product_type_name'])))); $arrFooter[0] = array('value' => $GLOBALS['TL_LANG']['ISO_REPORT']['sums']); foreach ($arrColumns as $i => $column) { $arrRow[$i + 1] = array('value' => Isotope::formatPriceWithCurrency($arrProduct[$column]) . ($arrProduct[$column . '_quantity'] !== null ? '<br><span class="variant">' . Isotope::formatItemsString($arrProduct[$column . '_quantity']) . '</span>' : '')); $arrFooter[$i + 1] = array('total' => $arrFooter[$i + 1]['total'] + $arrProduct[$column], 'quantity' => $arrFooter[$i + 1]['quantity'] + $arrProduct[$column . '_quantity']); } $arrRow[$i + 2] = array('value' => Isotope::formatPriceWithCurrency($arrProduct['total']) . ($arrProduct['quantity'] !== null ? '<br><span class="variant">' . Isotope::formatItemsString($arrProduct['quantity']) . '</span>' : '')); $arrFooter[$i + 2] = array('total' => $arrFooter[$i + 2]['total'] + $arrProduct['total'], 'quantity' => $arrFooter[$i + 2]['quantity'] + $arrProduct['quantity']); $arrData['rows'][] = array('columns' => $arrRow); } for ($i = 1; $i < count($arrFooter); $i++) { $arrFooter[$i]['value'] = Isotope::formatPriceWithCurrency($arrFooter[$i]['total']) . '<br><span class="variant">' . Isotope::formatItemsString($arrFooter[$i]['quantity']) . '</span>'; unset($arrFooter[$i]['total']); } $arrData['footer'] = $arrFooter; $this->Template->data = $arrData; }
private function countProductsForFilter(array $filters) { $arrColumns = array(); $arrCategories = $this->findCategories(); $queryBuilder = new FilterQueryBuilder($filters); $arrColumns[] = "c.page_id IN (" . implode(',', $arrCategories) . ")"; // Apply new/old product filter if ($this->iso_newFilter == self::FILTER_NEW) { $arrColumns[] = Product::getTable() . ".dateAdded>=" . Isotope::getConfig()->getNewProductLimit(); } elseif ($this->iso_newFilter == self::FILTER_OLD) { $arrColumns[] = Product::getTable() . ".dateAdded<" . Isotope::getConfig()->getNewProductLimit(); } if ($this->iso_list_where != '') { $arrColumns[] = $this->iso_list_where; } if ($queryBuilder->hasSqlCondition()) { $arrColumns[] = $queryBuilder->getSqlWhere(); } return Product::countPublishedBy($arrColumns, $queryBuilder->getSqlValues()); }
/** * Show product name in breadcrumb * * @param array $arrItems * @param object $objModule * * @return array */ public function addProductToBreadcrumb($arrItems, $objModule) { if (\Haste\Input\Input::getAutoItem('product', false, true) != '') { $objProduct = Product::findAvailableByIdOrAlias(\Haste\Input\Input::getAutoItem('product', false, true)); if (null !== $objProduct) { global $objPage; global $objIsotopeListPage; $last = count($arrItems) - 1; // If we have a reader page, rename the last item (the reader) to the product title if (null !== $objIsotopeListPage) { $arrItems[$last]['title'] = $this->prepareMetaDescription($objProduct->meta_title ?: $objProduct->name); $arrItems[$last]['link'] = $objProduct->name; } else { $arrItems[$last]['href'] = \Controller::generateFrontendUrl($arrItems[$last]['data']); $arrItems[$last]['isActive'] = false; $arrItems[] = array('isRoot' => false, 'isActive' => true, 'href' => $objProduct->generateUrl($objPage), 'title' => $this->prepareMetaDescription($objProduct->meta_title ?: $objProduct->name), 'link' => $objProduct->name, 'data' => $objPage->row()); } } } return $arrItems; }
/** * Return the PayPal form. * * @param IsotopeProductCollection|Order $objOrder The order being places * @param \Module|Checkout $objModule The checkout module instance * * @return string */ public function checkoutForm(IsotopeProductCollection $objOrder, \Module $objModule) { $arrData = array(); $fltDiscount = 0; $i = 0; foreach ($objOrder->getItems() as $objItem) { // Set the active product for insert tags replacement if ($objItem->hasProduct()) { Product::setActive($objItem->getProduct()); } $strConfig = ''; $arrConfig = $objItem->getConfiguration(); if (!empty($arrConfig)) { array_walk($arrConfig, function (&$option) { $option = $option['label'] . ': ' . (string) $option; }); $strConfig = ' (' . implode(', ', $arrConfig) . ')'; } $arrData['item_number_' . ++$i] = $objItem->getSku(); $arrData['item_name_' . $i] = \StringUtil::restoreBasicEntities($objItem->getName() . $strConfig); $arrData['amount_' . $i] = $objItem->getPrice(); $arrData['quantity_' . $i] = $objItem->quantity; } foreach ($objOrder->getSurcharges() as $objSurcharge) { if (!$objSurcharge->addToTotal) { continue; } // PayPal does only support one single discount item if ($objSurcharge->total_price < 0) { $fltDiscount -= $objSurcharge->total_price; continue; } $arrData['item_name_' . ++$i] = $objSurcharge->label; $arrData['amount_' . $i] = $objSurcharge->total_price; } $objTemplate = new \Isotope\Template('iso_payment_paypal'); $objTemplate->setData($this->arrData); $objTemplate->id = $this->id; $objTemplate->action = 'https://www.' . ($this->debug ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr'; $objTemplate->invoice = $objOrder->id; $objTemplate->data = array_map('specialchars', $arrData); $objTemplate->discount = $fltDiscount; $objTemplate->address = $objOrder->getBillingAddress(); $objTemplate->currency = $objOrder->currency; $objTemplate->return = \Environment::get('base') . $objModule->generateUrlForStep('complete', $objOrder); $objTemplate->cancel_return = \Environment::get('base') . $objModule->generateUrlForStep('failed'); $objTemplate->notify_url = \Environment::get('base') . 'system/modules/isotope/postsale.php?mod=pay&id=' . $this->id; $objTemplate->headline = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][0]); $objTemplate->message = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][1]); $objTemplate->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][2]); $objTemplate->noscript = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][3]); return $objTemplate->parse(); }
/** * Generate item array for template * @param ProductCollectionItem * @return array */ protected function generateItem(ProductCollectionItem $objItem) { $blnHasProduct = $objItem->hasProduct(); $objProduct = $objItem->getProduct(); // Set the active product for insert tags replacement if ($blnHasProduct) { Product::setActive($objProduct); } $arrCSS = $blnHasProduct ? deserialize($objProduct->cssID, true) : array(); $arrItem = array('id' => $objItem->id, 'sku' => $objItem->getSku(), 'name' => $objItem->getName(), 'options' => Isotope::formatOptions($objItem->getOptions()), 'quantity' => $objItem->quantity, 'price' => Isotope::formatPriceWithCurrency($objItem->getPrice()), 'tax_free_price' => Isotope::formatPriceWithCurrency($objItem->getTaxFreePrice()), 'total' => Isotope::formatPriceWithCurrency($objItem->getTotalPrice()), 'tax_free_total' => Isotope::formatPriceWithCurrency($objItem->getTaxFreeTotalPrice()), 'tax_id' => $objItem->tax_id, 'href' => false, 'hasProduct' => $blnHasProduct, 'product' => $objProduct, 'item' => $objItem, 'raw' => $objItem->row(), 'rowClass' => trim('product ' . ($blnHasProduct && $objProduct->isNew() ? 'new ' : '') . $arrCSS[1])); if (null !== $objItem->getRelated('jumpTo') && $blnHasProduct && $objProduct->isAvailableInFrontend()) { $arrItem['href'] = $objProduct->generateUrl($objItem->getRelated('jumpTo')); } Product::unsetActive(); return $arrItem; }
/** * Return a widget object based on a product attribute's properties * @param string * @param boolean * @return string */ protected function generateProductOptionWidget($strField, &$arrVariantOptions, &$arrAjaxOptions) { \Controller::loadDataContainer(ProductModel::getTable()); $GLOBALS['TL_DCA'][ProductModel::getTable()]['fields']['gift_amount']['default'] = $GLOBALS['TL_DCA'][ProductModel::getTable()]['fields']['gift_amount']['default'] ?: Isotope::formatPrice($this->getPrice()->getAmount()); return parent::generateProductOptionWidget($strField, $arrVariantOptions, $arrAjaxOptions); }
/** * Add options from attribute to DCA * * @param array $arrData * @param object $objDca * * @return array */ public function addOptionsFromAttribute($arrData, $objDca) { if ($arrData['strTable'] == Product::getTable() && $arrData['optionsSource'] != '' && $arrData['optionsSource'] != 'foreignKey') { /** @var IsotopeAttributeWithOptions|Attribute $objAttribute */ $objAttribute = Attribute::findByFieldName($arrData['strField']); if (null !== $objAttribute && $objAttribute instanceof IsotopeAttributeWithOptions) { $arrOptions = $objDca instanceof IsotopeProduct ? $objAttribute->getOptionsForWidget($objDca) : $objAttribute->getOptionsForWidget(); if (!empty($arrOptions)) { if ($arrData['includeBlankOption']) { array_unshift($arrOptions, array('value' => '', 'label' => $arrData['blankOptionLabel'] ?: '-')); } $arrData['options'] = $arrOptions; if (null !== $arrData['default']) { $arrDefault = array_filter($arrOptions, function (&$option) { return (bool) $option['default']; }); if (!empty($arrDefault)) { array_walk($arrDefault, function (&$value) { $value = $value['value']; }); $arrData['value'] = $objAttribute->multiple ? $arrDefault : $arrDefault[0]; } } } } } return $arrData; }
/** * Get the product related to this item * * @param bool $blnNoCache * * @return \Isotope\Interfaces\IsotopeProduct|null */ public function getProduct($blnNoCache = false) { if (false === $this->objProduct || true === $blnNoCache) { $this->objProduct = null; /** @var \Isotope\Model\Product $strClass */ $strClass = Product::getClassForModelType($this->type); if ($strClass == '' || !class_exists($strClass)) { \System::log('Error creating product object of type "' . $this->type . '"', __METHOD__, TL_ERROR); return null; } $this->objProduct = $strClass::findByPk($this->product_id); } return $this->objProduct; }
/** * 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; }