Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidpeywasti committed Dec 5, 2014
1 parent 99d71d2 commit 39f9f28
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions dca/tl_catalog_product.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
'palettes' => array
(
'__selector__' => array('addEnclosure','published'),
'default' => '{title_legend},title,alias,date,featured;
'default' => '{title_legend},title,alias,featured,date;
{meta_legend},description,keywords;
{feature_legend},features;
{spec_legend},spec;
Expand Down Expand Up @@ -178,8 +178,12 @@
'search' => true,
'sorting' => true,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'rgxp'=>'alias','unique'=>true,'maxlength'=>10, 'tl_class'=>'w50'),
'sql' => "varchar(10) NOT NULL default ''"
'eval' => array('mandatory'=>true, 'rgxp'=>'alias','unique'=>true,'maxlength'=>128, 'tl_class'=>'w50'),
'save_callback' => array
(
array('tl_catalog_product', 'generateAlias')
),
'sql' => "varchar(128) NOT NULL default ''"
),
'date' => array
(
Expand Down Expand Up @@ -288,7 +292,7 @@
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'w50'),
'eval' => array('tl_class'=>'w50 m12'),
'sql' => "char(1) NOT NULL default ''"
),
'start' => array
Expand Down Expand Up @@ -316,6 +320,42 @@
class tl_catalog_product extends Backend
{

/**
* Auto-generate the product alias if it has not been set yet
* @param mixed
* @param \DataContainer
* @return string
* @throws \Exception
*/
public function generateAlias($varValue, DataContainer $dc)
{
$autoAlias = false;

// Generate alias if there is none
if ($varValue == '')
{
$autoAlias = true;
$varValue = standardize(String::restoreBasicEntities($dc->activeRecord->title));
}

$objAlias = $this->Database->prepare("SELECT id FROM tl_catalog_product WHERE alias=?")
->execute($varValue);

// Check whether the news alias exists
if ($objAlias->numRows > 1 && !$autoAlias)
{
throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
}

// Add ID to alias
if ($objAlias->numRows && $autoAlias)
{
$varValue .= '-' . $dc->id;
}

return $varValue;
}

/**
* Generate a song row and return it as HTML string
* @param array
Expand Down

0 comments on commit 39f9f28

Please sign in to comment.