Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

% discount on prices
 
sfumato
Member
 
Total Posts:  40
Joined:  2008-12-26
 

Hello,

I tried installing the % discount on my magento. I got the info from http://www.magentocommerce.com/wiki/customizing_magento_using_event-observer_method

I followed the instruction but I got this error.

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 2: parser error : XML declaration allowed only at the start of the document in lib/Varien/Simplexml/Config.php on line 500
Trace:
#0 [internal function]: mageCoreErrorHandler(2, ‘simplexml_load_...’, ‘/home/futonfac/...’, 500, Array)
#1 lib/Varien/Simplexml/Config.php(500): simplexml_load_string(’??  loadString(’??  loadFile(’/home/futonfac/...’)
#4 app/code/core/Mage/Core/Model/App.php(236): Mage_Core_Model_Config->init(Array)
#5 app/Mage.php(424): Mage_Core_Model_App->init(’’, ‘store’, Array)
#6 app/Mage.php(443): Mage::app(’’, ‘store’, Array)
#7 index.php(52): Mage::run()
#8 {main}

I don’t know what I did wrong..or if there something missing that I didn’t do.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

in which xml did you add your observer data? check this xml for validation.

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
sfumato
Member
 
Total Posts:  40
Joined:  2008-12-26
 
[m><p> zentrale” date= -

in which xml did you add your observer data? check this xml for validation.

cheers

Hi Zentrale,

I created the observer data as the instructions said. In app/code/local/Xyz/Catalog/Model/Price/

Created Observer.php

And this is the code:

<?php

class Xyz_Catalog_Model_Price_Observer

{

public function __construct()

{

}

/**

* Applies the special price percentage discount

* @param Varien_Event_Observer $observer

* @return Xyz_Catalog_Model_Price_Observer

*/

public function apply_discount_percent($observer)

{

$event = $observer->getEvent();

$product = $event->getProduct();

// process percentage discounts only for simple products

if($product->getSuperProduct() && $product->getSuperProduct()->isConfigurable()) {

} else {

$percentDiscount = $product->getPercentDiscount();



if (is_numeric($percentDiscount)) {

$today = floor(time()/86400)*86400;

$from = floor(strtotime($product->getSpecialFromDate())/86400)*86400;

$to = floor(strtotime($product->getSpecialToDate())/86400)*86400;



if ($product->getSpecialFromDate() && $today < $from) {

} elseif ($product->getSpecialToDate() && $today > $to) {

} else {

$price = $product->getPrice();

$finalPriceNow = $product->getData(’final_price’);



$specialPrice = $price - $price * $percentDiscount / 100;



// if special price is negative - negate the discount - this may be a mistake in data

if( $specialPrice < 0) $specialPrice = $finalPriceNow;



if ($specialPrice < $finalPriceNow)

$product->setFinalPrice($specialPrice); // set the product final price

}

}

}

return $this;

}

}

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

this is not a php error, you have a error/mismatching note, not well formed xml file. Which file did you change last?
Check your config.xml of your module

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top