/** * Multiple-fields (e.g. select or checkbox) with numberic keys are stored as CSV to improve filters. */ private function convertSerializedValues() { $t = Attribute::getTable(); $fields = array(); $attributes = Attribute::findBy(array("{$t}.multiple='1' AND {$t}.optionsSource='foreignKey'"), null); if (null !== $attributes) { /** @var Attribute $attribute */ foreach ($attributes as $attribute) { if ($attribute instanceof IsotopeAttributeWithOptions) { $fields[] = $attribute->field_name; } } } if (!empty($fields)) { /** @var \Database\Result|object $products */ $products = $this->db->execute("\n SELECT id, " . implode(', ', $fields) . "\n FROM tl_iso_product\n WHERE " . implode(" IS NOT NULL OR ", $fields) . " IS NOT NULL\n "); while ($products->next()) { $set = array(); foreach ($fields as $field) { $value = deserialize($products->{$field}); if (!empty($value) && is_array($value)) { $set[$field] = implode(',', $value); } } if (!empty($set)) { $this->db->prepare("UPDATE tl_iso_product %s WHERE id=?")->set($set)->execute($products->id); } } } }
/** * @param $arrData * @param $id * @return bool */ public function saveAttributeOptions($arrData, $id) { $arrAttributeOptions = array(); $time = time(); $ptable = \Isotope\Model\Attribute::getTable(); foreach ($arrData as $group => $groupData) { if (is_array($groupData)) { $arrAttributeOptions[] = array('pid' => $id, 'sorting' => 0, 'tstamp' => $time, 'ptable' => $ptable, 'type' => 'group', 'label' => $group, 'published' => 1); foreach ($groupData as $optionData) { if (is_array($optionData)) { //@todo if there are more options } else { $arrAttributeOptions[] = array('pid' => $id, 'sorting' => 0, 'tstamp' => $time, 'ptable' => $ptable, 'type' => 'option', 'label' => $optionData, 'published' => 1); } } } else { $arrAttributeOptions[] = array('pid' => $id, 'sorting' => 0, 'tstamp' => $time, 'ptable' => $ptable, 'type' => 'option', 'label' => $groupData, 'published' => 1); } } $sorting = 0; foreach ($arrAttributeOptions as $arrData) { $objAttributeOption = new AttributeOption(); $objAttributeOption->setRow($arrData); $objAttributeOption->sorting = $sorting; $objAttributeOption->save(); $sorting += 128; } return true; }
/** * 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; }
/** * Notification Center notification types */ $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['recipients'] = array('recipient_email'); $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['attachment_tokens'] = array('form_*', 'document'); $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['email_text'] = array('uniqid', 'order_status', 'order_status_old', 'order_status_id', 'order_status_id_old', 'recipient_email', 'order_id', 'order_items', 'order_products', 'order_subtotal', 'order_total', 'document_number', 'cart_html', 'cart_text', 'document', 'billing_address', 'billing_address_*', 'shipping_address', 'shipping_address_*', 'form_*', 'payment_id', 'payment_label', 'payment_note', 'shipping_id', 'shipping_label', 'shipping_note', 'config_*', 'member_*'); $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['email_subject'] =& $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['email_text']; $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['email_html'] =& $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['email_text']; $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['email_replyTo'] =& $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['recipients']; $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['email_recipient_cc'] =& $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope']['iso_order_status_change']['recipients']; $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';
/** * Build palette for the current product type/variant */ public function buildPaletteString() { $this->loadDataContainer(Attribute::getTable()); if (\Input::get('act') == '' && \Input::get('key') == '' || \Input::get('act') == 'select') { return; } $arrTypes = array(); $arrFields =& $GLOBALS['TL_DCA']['tl_iso_product']['fields']; /** @var IsotopeAttribute[] $arrAttributes */ $arrAttributes =& $GLOBALS['TL_DCA']['tl_iso_product']['attributes']; $blnVariants = false; $act = \Input::get('act'); $blnSingleRecord = $act === 'edit' || $act === 'show'; if (\Input::get('id') > 0) { /** @type object $objProduct */ $objProduct = \Database::getInstance()->prepare("SELECT p1.pid, p1.type, p2.type AS parent_type FROM tl_iso_product p1 LEFT JOIN tl_iso_product p2 ON p1.pid=p2.id WHERE p1.id=?")->execute(\Input::get('id')); if ($objProduct->numRows) { $objType = ProductType::findByPk($objProduct->pid > 0 ? $objProduct->parent_type : $objProduct->type); $arrTypes = null === $objType ? array() : array($objType); if ($objProduct->pid > 0 || $act != 'edit' && $act != 'copyFallback' && $act != 'show') { $blnVariants = true; } } } else { $arrTypes = ProductType::findAllUsed() ?: array(); } /** @var \Isotope\Model\ProductType $objType */ foreach ($arrTypes as $objType) { // Enable advanced prices if ($blnSingleRecord && $objType->hasAdvancedPrices()) { $arrFields['prices']['exclude'] = $arrFields['price']['exclude']; $arrFields['prices']['attributes'] = $arrFields['price']['attributes']; $arrFields['price'] = $arrFields['prices']; } else { $GLOBALS['TL_DCA']['tl_iso_product']['config']['onversion_callback'][] = array('Isotope\\Backend\\Product\\Price', 'createVersion'); $GLOBALS['TL_DCA']['tl_iso_product']['config']['onrestore_callback'][] = array('Isotope\\Backend\\Product\\Price', 'restoreVersion'); } $arrInherit = array(); $arrPalette = array(); $arrLegends = array(); $arrLegendOrder = array(); $arrCanInherit = array(); if ($blnVariants) { $arrConfig = $objType->variant_attributes; $arrEnabled = $objType->getVariantAttributes(); $arrCanInherit = $objType->getAttributes(); } else { $arrConfig = $objType->attributes; $arrEnabled = $objType->getAttributes(); } // Go through each enabled field and build palette foreach ($arrFields as $name => $arrField) { if (in_array($name, $arrEnabled)) { if ($arrField['inputType'] == '') { continue; } // Variant fields can only be edited in variant mode if (null !== $arrAttributes[$name] && !$blnVariants && $arrAttributes[$name]->isVariantOption()) { continue; } // Field cannot be edited in variant if ($blnVariants && $arrAttributes[$name]->inherit) { continue; } $arrLegendOrder[$arrConfig[$name]['position']] = $arrConfig[$name]['legend']; $arrPalette[$arrConfig[$name]['legend']][$arrConfig[$name]['position']] = $name; // Apply product type attribute config if ($arrConfig[$name]['tl_class'] != '') { $arrFields[$name]['eval']['tl_class'] = $arrConfig[$name]['tl_class']; } if ($arrConfig[$name]['mandatory'] > 0) { $arrFields[$name]['eval']['mandatory'] = $arrConfig[$name]['mandatory'] == 1 ? false : true; } if ($blnVariants && in_array($name, $arrCanInherit) && null !== $arrAttributes[$name] && !$arrAttributes[$name]->isVariantOption() && !in_array($name, array('price', 'published', 'start', 'stop'))) { $arrInherit[$name] = Format::dcaLabel('tl_iso_product', $name); } } else { // Hide field from "show" option if (!isset($arrField['attributes']) || $arrField['inputType'] != '' && $name != 'inherit') { $arrFields[$name]['eval']['doNotShow'] = true; } } } ksort($arrLegendOrder); $arrLegendOrder = array_unique($arrLegendOrder); // Build foreach ($arrLegendOrder as $legend) { $fields = $arrPalette[$legend]; ksort($fields); $arrLegends[] = '{' . $legend . '},' . implode(',', $fields); } // Set inherit options $arrFields['inherit']['options'] = $arrInherit; // Add palettes $GLOBALS['TL_DCA']['tl_iso_product']['palettes'][$blnVariants ? 'default' : $objType->id] = ($blnVariants ? 'inherit,' : '') . implode(';', $arrLegends); } // Remove non-active fields from multi-selection if ($blnVariants && !$blnSingleRecord) { $arrInclude = empty($arrPalette) ? array() : call_user_func_array('array_merge', $arrPalette); foreach ($arrFields as $name => $config) { if ($arrFields[$name]['attributes']['legend'] != '' && !in_array($name, $arrInclude)) { $arrFields[$name]['exclude'] = true; } } } }