Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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] = '&nbsp;';
                 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')) . '&amp;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>&nbsp;' . Format::dcaValue($dc->table, $variantField, $objProduct->{$variantField});
                 }
                 $args[$i] = ($args[$i] ? $args[$i] . '<br>' : '') . implode(', ', $attributes);
                 break;
         }
     }
     return $args;
 }
Ejemplo n.º 3
0
 /**
  * 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));
 }
 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;
 }
Ejemplo n.º 5
0
 /**
  * Change the displayed columns in the variants view
  */
 public function changeVariantColumns()
 {
     if (\Input::get('act') != '' && \Input::get('act') != 'select' || \Input::get('id') == '' || ($objProduct = Product::findByPk(\Input::get('id'))) === null) {
         return;
     }
     $GLOBALS['TL_DCA'][$objProduct->getTable()]['list']['sorting']['mode'] = 4;
     $GLOBALS['TL_DCA'][$objProduct->getTable()]['list']['sorting']['fields'] = array('id');
     $GLOBALS['TL_DCA'][$objProduct->getTable()]['fields']['alias']['sorting'] = false;
     $arrFields = array();
     /** @type ProductType $objType */
     $objType = $objProduct->getRelated('type');
     $arrVariantFields = $objType->getVariantAttributes();
     $arrVariantOptions = array_intersect($arrVariantFields, Attribute::getVariantOptionFields());
     if (in_array('images', $arrVariantFields)) {
         $arrFields[] = 'images';
     }
     if (in_array('name', $arrVariantFields)) {
         $arrFields[] = 'name';
         $GLOBALS['TL_DCA'][$objProduct->getTable()]['list']['sorting']['fields'] = array('name');
     }
     if (in_array('sku', $arrVariantFields)) {
         $arrFields[] = 'sku';
         $GLOBALS['TL_DCA'][$objProduct->getTable()]['list']['sorting']['fields'] = array('sku');
     }
     if (in_array('price', $arrVariantFields)) {
         $arrFields[] = 'price';
     }
     // Limit the number of columns if there are more than 2
     if (count($arrVariantOptions) > 2) {
         $arrFields[] = 'variantFields';
         $GLOBALS['TL_DCA'][$objProduct->getTable()]['list']['label']['variantFields'] = $arrVariantOptions;
     } else {
         foreach (array_merge($arrVariantOptions) as $name) {
             /** @type Attribute $objAttribute */
             $objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$name];
             if ($objAttribute instanceof IsotopeAttributeWithOptions && $objAttribute->optionsSource == 'table') {
                 $name .= ':tl_iso_attribute_option.label';
             }
             $arrFields[] = $name;
         }
     }
     $GLOBALS['TL_DCA'][$objProduct->getTable()]['list']['label']['fields'] = $arrFields;
     // Make all column fields sortable
     foreach ($GLOBALS['TL_DCA'][$objProduct->getTable()]['fields'] as $name => $arrField) {
         $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$name]['sorting'] = $name != 'price' && $name != 'variantFields' && in_array($name, $arrFields);
         $objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$name];
         $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$name]['filter'] = $objAttribute->be_filter ? in_array($name, $arrVariantFields) : false;
         $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$name]['search'] = $objAttribute->be_search ? in_array($name, $arrVariantFields) : false;
     }
 }
Ejemplo n.º 6
0
    /**
     * Generate all combination of product attributes
     * @param object
     * @return string
     */
    public function generate($dc)
    {
        $table = Product::getTable();
        $objProduct = Product::findByPk($dc->id);
        $doNotSubmit = false;
        $strBuffer = '';
        $arrOptions = array();
        foreach ($objProduct->getRelated('type')->getVariantAttributes() as $attribute) {
            if ($GLOBALS['TL_DCA'][$table]['fields'][$attribute]['attributes']['variant_option']) {
                $GLOBALS['TL_DCA'][$table]['fields'][$attribute]['eval']['mandatory'] = true;
                $GLOBALS['TL_DCA'][$table]['fields'][$attribute]['eval']['multiple'] = true;
                $arrField = \CheckBox::getAttributesFromDca($GLOBALS['TL_DCA'][$table]['fields'][$attribute], $attribute);
                foreach ($arrField['options'] as $k => $option) {
                    if ($option['value'] == '') {
                        unset($arrField['options'][$k]);
                    }
                }
                $objWidget = new \CheckBox($arrField);
                if (\Input::post('FORM_SUBMIT') == $table . '_generate') {
                    $objWidget->validate();
                    if ($objWidget->hasErrors()) {
                        $doNotSubmit = true;
                    } else {
                        $arrOptions[$attribute] = $objWidget->value;
                    }
                }
                $strBuffer .= $objWidget->parse();
            }
        }
        if (\Input::post('FORM_SUBMIT') == $table . '_generate' && !$doNotSubmit) {
            $time = time();
            $arrCombinations = array();
            foreach ($arrOptions as $name => $options) {
                $arrTemp = $arrCombinations;
                $arrCombinations = array();
                foreach ($options as $option) {
                    if (empty($arrTemp)) {
                        $arrCombinations[][$name] = $option;
                        continue;
                    }
                    foreach ($arrTemp as $temp) {
                        $temp[$name] = $option;
                        $arrCombinations[] = $temp;
                    }
                }
            }
            foreach ($arrCombinations as $combination) {
                $objVariant = \Database::getInstance()->prepare("\n                    SELECT * FROM {$table} WHERE pid=? AND " . implode('=? AND ', array_keys($combination)) . "=?")->execute(array_merge(array($objProduct->id), $combination));
                if (!$objVariant->numRows) {
                    $arrInherit = array_diff($objProduct->getRelated('type')->getVariantAttributes(), Attribute::getVariantOptionFields(), Attribute::getCustomerDefinedFields(), Attribute::getSystemColumnsFields());
                    $arrSet = array_merge($combination, array('tstamp' => $time, 'pid' => $objProduct->id, 'inherit' => $arrInherit ?: null));
                    \Database::getInstance()->prepare("INSERT INTO {$table} %s")->set($arrSet)->execute();
                }
            }
            \Controller::redirect(str_replace('&key=generate', '', \Environment::get('request')));
        }
        // Return form
        return '
<div id="tl_buttons">
<a href="' . ampersand(str_replace('&key=generate', '', \Environment::get('request'))) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBT']) . '">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>

<h2 class="sub_headline">' . sprintf($GLOBALS['TL_LANG'][$table]['generate'][1], $dc->id) . '</h2>' . \Message::generate() . '

<form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $table . '_generate" class="tl_form" method="post">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="' . $table . '_generate">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">

<div class="tl_tbox block">
' . $strBuffer . '
</div>

</div>

<div class="tl_formbody_submit">

<div class="tl_submit_container">
  <input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['tl_iso_product']['generate'][0]) . '">
</div>

</div>
</form>';
    }
Ejemplo n.º 7
0
 /**
  * List the products
  * @param array
  * @return string
  */
 public function listRows($row)
 {
     $objProduct = Product::findByPk($row['pid']);
     return $objProduct->name;
 }