/** * Show price column in dcaWizard if attribute is not a variant option * * @param \Widget|object $objWidget * * @return string */ public function initializeTableOptions(\Widget $objWidget) { /** @type Attribute $objAttribute */ if (\Input::get('do') == 'iso_products') { $objAttribute = Attribute::findByFieldName($objWidget->name); } else { $objAttribute = Attribute::findByPk(\Input::get('id')); } if (null !== $objAttribute && !$objAttribute->isVariantOption()) { $objWidget->fields = array_merge($objWidget->fields, array('price')); } return AttributeOption::getTable(); }
/** * 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 formatted label for the attribute option * * @param IsotopeProduct $objProduct * * @return string */ public function getLabel(IsotopeProduct $objProduct = null) { $strLabel = $this->label; /** @type Attribute $objAttribute */ $objAttribute = null; switch ($this->ptable) { case 'tl_iso_product': $objAttribute = Attribute::findByFieldName($this->field_name); break; case 'tl_iso_attribute': $objAttribute = Attribute::findByPk($this->pid); break; } if (null !== $objAttribute && !$objAttribute->isVariantOption() && $this->price != '') { $strLabel .= ' ('; if (!$this->isPercentage() || null !== $objProduct) { $strPrice = Isotope::formatPriceWithCurrency($this->getPrice($objProduct), false); } else { $strPrice = $this->price; } $strLabel .= $this->isFromPrice($objProduct) ? sprintf($GLOBALS['TL_LANG']['MSC']['priceRangeLabel'], $strPrice) : $strPrice; $strLabel .= ')'; } return $strLabel; }