[TYPO3-commerce] Special offers/rebate or other kind of reductions
Simon Lang
blubbfish at gmail.com
Tue Aug 28 10:47:02 CEST 2007
Thanks alot for the help.
I added an additional field "crossedprice" to the table
tx_commerce_article_prices and a field to the Dynaflex form in the
"Prices" tab in the articles record.
The crossed price is displayed in an additional marker in the frontend.
It works now, but has one small bug. I post my solution below for the
community.
My problem:
When I edit an article, the crossed price is displayed in the Dynaflex
form (everything good so far). After I save the article, the field
magically vanishes. When I reenter the Dynaflex prices form, its there
again (and the value is correctly written to the database).
Does somebody has an idea how to fix this?
Regards
=======================================
== ext_tables.php (of any extension) ==
=======================================
//Adding the crossed price to the price dynaflex.
$tempConf = array(
'TCEforms' => array(
'label' =>
'LLL:EXT:commerceextender/locallang_db.xml:tx_commerce_article_prices.tx_commerceextender_crossedprice',
'config' => array(
'type' => 'input',
'size' => 15,
),
),
);
$insertAfter = 'price_net';
$fieldName = 'tx_commerceextender_crossedprice_';
t3lib_div::loadTCA('tx_commerce_articles');
$dynaFlexConf =
t3lib_div::xml2array($TCA['tx_commerce_articles']['columns']['prices']['config']['ds']['default']);
$insertIds = array();
//Add for each price a crossed price field.
foreach ($dynaFlexConf['ROOT']['el'] as $key => $value) {
$tempDynaFlexConf[$key] = $value;
if (strpos($key, '_') !== false) {
$keyData = @explode('_', $key);
if (is_array($keyData)) {
$priceId = intval($keyData[(count($keyData) -1)]);
//Strip the id away from the key so it can be compared with
the $insertAfter
unset($keyData[(count($keyData) -1)]);
$key = implode('_', $keyData);
}
}
if ($key == $insertAfter) {
$tempDynaFlexConf[$fieldName.$priceId] = $tempConf;
}
}
$dynaFlexConf['ROOT']['el'] = $tempDynaFlexConf;
$TCA['tx_commerce_articles']['columns']['prices']['config']['ds']['default']
= t3lib_div::array2xml($dynaFlexConf);
//Adding the crossed price database field to the
tx_commerce_article_prices database.
$tempColumns = Array (
"tx_commerceextender_crossedprice" => Array (
"exclude" => 1,
"label" =>
"LLL:EXT:commerceextender/locallang_db.xml:tx_commerce_article_prices.tx_commerceextender_crossedprice",
"config" => Array (
"type" => "input",
"size" => "30",
)
),
);
t3lib_div::loadTCA('tx_commerce_article_prices');
t3lib_extMgm::addTCAcolumns('tx_commerce_article_prices',$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes('tx_commerce_article_prices','tx_commerceextender_crossedprice','','after:price_net');
===============================================
== ext_localconf.php (of same extension :o)) ==
===============================================
//Hook for adding the crossed price field to the article price object.
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_article_price.php']['postinit'][]="EXT:commerceextender/class.tx_commerceextender_articleview.php:&tx_commerceextender_articleview";
//Hook for adding the crossed price to the article view.
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['articleview'][]="EXT:commerceextender/class.tx_commerceextender_articleview.php:&tx_commerceextender_articleview";
========================================================================
== class.tx_commerceextender_articleview.php (or something like that) ==
========================================================================
/**
* Hook for the commerce article view.
*
* @author Simon Lang <slang at snowflake.ch>
* @package TYPO3
* @subpackage tx_commerce
*/
class tx_commerceextender_articleview {
/**
* This hookmethod will be called after the initalisation of the
article price object and adds the crossed price field to the fieldlist.
* This will add the field to the db query and is then available in
the article price object.
*
* @param tx_commerce_article_price $pObj: The article price
object.
*/
function postinit($pObj) {
$pObj->fieldlist[] = 'tx_commerceextender_crossedprice';
}
/**
* Adds the crossed price field to the marker array.
*
* @param String[] $markerArray: The marker array.
* @param tx_commerce_pi1 $pObj: The parent object.
* @param tx_commcerc_article $article: The article object.
* @return String[] The modified marker array
*/
function additionalMarker($markerArray, $pObj, $article) {
$price = $article->price->tx_commerceextender_crossedprice;
//"12333.32" has to look like "1233332" and "12333" has to look
like 1233300". Else its not correctly formated by the tx_moneylib.
//Normaly thats done in the class.tx_commerce_dmhooks.php. But
there is no hook or another way to hook in. So do manualy.
//Check if there is a comma or a point in the price.
if (stristr($price, ',') || stristr($price, '.')) {
//Strip commas or points away.
$price = str_replace(array(',','.'), '', $price);
} else {
//Add two additional zeros.
$price.= '00';
}
//Format the price and put it into the marker array.
$markerArray['ARTICLE_PRICE_CROSSED'] =
tx_moneylib::format($price,$pObj->currency);
return $markerArray;
}
}
Ingo Schmitt schrieb:
> Hi Simon,
>
>> Hi Guys!
>>
>> Does commerce support "special offers" / "rebates"?
>> I need to display two prices in the frontend, where one price is
>> crossed out. I have seen a working example of this on
>> http://www.hpnielsen.dk. The later is actually using commerce, so it
>> should be possible. I would like to know wether that is a feature or
>> if one has to use hooks in order to achieve this.
>>
> I think the guys from typoconsult have added a own database field
> (crossed price) by an own extension to have this crossed price. Have a
> look at the hooks in tx_commerce_element_alib, which is the basic calss
> for the commerce objects.
>
> ingo
>
>> Regards
>
>
> Mit freundlichen Gruessen
More information about the TYPO3-project-commerce
mailing list