Just though I would share this little tid bit for the benefit of all who have asked for this type of functionality from magento and not been prepared to pay $64 USD for an extension to do so.
Just to clarify, this is a mod, not an extension. Also, I’m not the worlds greatest Magento user and i’m sure there is a way of making an extension to do this. But.. for the moment, the following instructional works very well and is very easy to do.
Usage: Once mods have been made, admin users will be able to create a shopping cart rule “discount” which is not actually a discount based on a percentage of the value of their shopping cart. I’m not going to educate you all how to make a shopping cart rule, but basically, until now there have been a few problems with using shopping cart rules to apply a Surcharge.
The First. You can’t. You can only enter a positive number as a percentage
The Second. Magento in all their wisdom have an option to calculate the “discount” on shipping as well as shopping cart value, however the stupid system does not allow you to move the location of the “discount” / surcharge to after the shipping line. This can be very confusing for customers trying to figure out how their “discount”/surcharge is calculated.
Lastly, again in all their Wisdom, Magento went and hard coded the word “Discount” in front of the name of your discount / surcharge. So for instance if I wanted to add a surcharge using the mod below, it would read something like this :
(Discount) Credit Card Surcharge 1.5% = $15.60
Obviously that is not the smartest way to do things which is surprising for an E-Commerce system which is supposed to be flexible. Did they need to hard code the word “Discount” especially given the fact one could easily pre pend the word “discount” in the name of the shopping cart rule if they wanted it displayed.
One more gripe before I proceed to the How to is the fact the only reason I wrote this is because Magento are so pathetically poor at answer extreemly simple questions such as this. I could find absolutely no definitive solution to this issue other than to A) Pay Magento for support – which is laughable given how easy this was to resolve or B)Pay $64 for an extension.
And for the disclaimer. This will involve very small modifications to core Magento files. Always make backups before changing any of the files mentioned herin. Also apparently it is illegal to apply Credit Card (or any other payment type for that matter) surcharges in some countries. Check with your Merchant provider in your country to see if this is a problem.
Let me know if you have any questions and please provide credit if you intend on posting this elsewhere.
MAGNETO CHANGES :
To create credit card surcharge :
Change the following file :
app/code/core/Mage/rule/model/rule.php
Find :
protected function _beforeSave()
{
check if discount amount > 0
if ((int)$this->getDiscountAmount() < 0) {
Mage::throwException(Mage::helper(‘rule’)->__(‘Invalid discount amount.’));
}
Change to :
protected function _beforeSave()
{
// check if discount amount > 0
//if ((int)$this->getDiscountAmount() < 0) {
// Mage::throwException(Mage::helper(‘rule’)->__(‘Invalid discount amount.’));
//}
Change the following file :
app/code/core/Mage/Adminhtml/block/promo/quote/edit/tab/actions.php
Find :
$fieldset->addField(‘discount_amount’, ‘text’, array(
‘name’ => ‘discount_amount’,
‘required’ => true,
‘class’ => ‘validate-not-negative-number’,
‘label’ => Mage::helper(‘salesrule’)->__(‘Discount amount’),
Change to :
$fieldset->addField(‘discount_amount’, ‘text’, array(
‘name’ => ‘discount_amount’,
‘required’ => true,
// ‘class’ => ‘validate-not-negative-number’,
‘label’ => Mage::helper(‘salesrule’)->__(‘Discount amount’),
Find :
app/locale/en_us/mage_sales.csv <–you may be using a different language definition file folder ie /en_au – copy changed file to both folders.
This part is important : open the file in Excel the first column is the variable name, the second is the variable value. ONLY CHANGE THE VARIABLE VALUE!! DO NOT CHANGE THE
VARIABLE NAME.
Find the row which says “Discount” in column 1 and “Discount” in column 2.
Erase the value of Discount in Column 2 ie Column 1 should read “Discount” (without the inverted commas) and column 2 should be empty.
The next step is optional and will depend if you want your surcharge to show AFTER shipping or before shipping. The Magento default is to display discounts (surcharge) BEFORE shipping- regardless of whether you’ve opted to have your surcharge/discount applied to shipping in the admin console. If you wish to have discount/surcharge displayed AFTER shipping, then proceed with the next step. Otherwise you’re all done.
Change the following file ***THIS STEP IS OPTIONAL AND IS SUITED TO VERSIONS LOWER THAN 1.4.01 For versions Later than 1.4.01 This change can be made via the admin console Admin ->Sales – >Checkout Total Sort Order. Change “Shipping” to “20″ and change the blank line above it to 30.
For versions prior to 1.4.01
app/code/core/Mage/Sales/etc/config.xml
Change the following :
<totals_sort>
<discount>20</discount>
<grand_total>100</grand_total>
<shipping>30</shipping>
<subtotal>10</subtotal>
<tax>40</tax>
</totals_sort>
To:
<totals_sort>
<discount>30</discount>
<grand_total>100</grand_total>
<shipping>20</shipping>
<subtotal>10</subtotal>
<tax>40</tax>
</totals_sort>
All Done. You should now be able to set negative values in the “Shopping Cart Price Rules” from your admin console. Make sure all rule names are descriptive so your customers know what is going on.
Login options
Glad you liked it. Would you like to share?
No thanks
Thanks! Close
Add New Comment
Showing 33 comments
$cModelData = $cModel->getData();
echo $cModelData->sku;
This code isnt working. It should be following….
$cModelData = $cModel->getData();
echo $cModelData['sku'];
Because $cModel->getData() is returning array, it need to be accessed as an array element. Arrow operator here will give error.
There are number of articles and even some extensions you can download from this site that should cover your question.
This post is useful to get data. My question is…
How can I store new record into the database…?
i have one question…
when i write getData method it will give me proper data…but i am edit that data ..and now i want to save it.. so how can i save that data ???
example : i make one attribute..now i fetch it on product view page now on add to cart i want to save that attribute data. so how can i do this thing ??
thank you..
Actually you can use full class name like
$product = new Mage_Model_Catalog_Product();
$product->load($productId);
I have put the code in this comment in case some people are still struggling to get the desired results -:
This code you can copy as it is in /template/catalog/product/view.phtml file.
$_helper = $this->helper(‘catalog/output’);
$_product = $this->getProduct();
$cModel_PC = Mage::getModel(‘catalog/product’);
echo ”;
foreach (get_class_methods(get_class($cModel_PC)) as $cMethod) {
echo ” . $cMethod . ”;
}
echo ”;
echo ‘====’;
echo ”;
foreach (get_class_methods(get_class($_helper)) as $cMethod) {
echo ” . $cMethod . ”;
}
echo ”;
$cModel_PC->load($_helper->productAttribute($_product, $this->htmlEscape($_product->getId()), ‘Id’));
echo $cModel_PC->getData(‘description’);
echo $cModel_PC->getData(‘name’);
echo $cModel_PC->getData(‘manufacture’);
$attributes = Mage::getModel(‘catalog/product/attribute’);
… doesn’t work. Oddly enough, it returns the Product object.
$idParams = $this->getRequest()->getParam(‘id’);
$cModel = Mage::getModel(‘catalog/product’);
$cModel->load($idParams);
print_r($cModel->getSku());
but even when I’m not on a product page, it still takes the ID of the page I’m on and runs it agains the product database and returns an SKU for whatever product I have that is matching up to the category page I’m on id-wise.
Is there a different way to find what the current product is that’s being displayed?
Thank You so much for your tutorials. They are straightforward and easy to read, unlike the offical source.
$cModel->getData(‘manufacturer’) returns an integer (index key).
How do we retrieve the text associated with it ?
I just wanna ask it is possible to add some customized functionality when I clicked on the “Place Order” in onestepcheckout say.. after performing the place order request… a new page will open in a separate window..
In that sense, we want to somehow edit the behavior when “Place Order” is clicked
How would you recommend creating a new root category using Mage::getModel(‘catalog/category’)?
Thank you,
Bob Brodie
thank u for nice post. it is very very useful post..
thank you man
http://www.magentocommerce.com/boards/viewthread/41408/
So if you can guide me than it will really help me to understand magento to great extent. One more thing, we can filter collection by attribute and if I want to filter my collection with field then how can I do this. Thanks in advance brother to guide me.
Second thing I want to display some attributes to my customer dashboard page where I am displaying the item list of all order’s. So please guide me.
thanks for nice Article
But i am in wonder that how do i read the Random Quotes through a
file in magento.Is Magento support such features or Zend Provides some built-in Libraries for that.
Please reply
can u tell me how magento search works i wanted to know where and how magento form the query so that i can customize that query.
actually i need to add one more parameter while it search for a product.
please throw some light. ASAP.
I was wondering how I shoul use those functions to display the product details (image, descriptions…) in a light popup clicking on an image to avoid reloading the page.
What should be the best way to do it, passing the product id to a js-php file that will create an instance of Mage_Catalog_Model_Product class, then load data?
Could I pass the array variable $_product to dynamically generate the detail product popup ?
Your suggestions are welcome
.
Sylvie
Thank you for for reading my blog. This is relatively old article now
Not sure what exactly you are trying to do in your example. Take a look at inchoo.net site (company I work for). You’ll find few additional Magento articles by me and my co-workers.
Cheers…
thanx a lot this article proved to be very useful for me.
just one doubt please clarify it:
My only idea is to get an array of all product ids then have a php function randomly pick one out and get the details via a $cModel->load(); and write it, then repeat!!
Seems a bit long winded,
is there not any way so that i can put any variable in load so that it could retrieve all the product information
Anyway, nice job with this blog,man. I found it very useful. Keep up the good work!
$cSingleton = Mage::getSingleton(‘catalog/product’);
echo ”;
echo ‘Product name:’;
echo $cSingleton->getName();
echo ”;
but I still can’t figure out how to retrieve the name of the product on the page from within the breadcrumbs. Anybody?
i need a bit explanation on this sentence of your post in sense of custom modules:
” In short getModel(’catalog/product’) says go into the /app/code/core/Mage/ folder, open the folder named product, and create an instance of Product.php file located inside the Model subfolder (to be more precise, create the instance of the class cotained inside the Product.php file).”
you told in above that getModel(’catalog/product’) will tell megento to pick the module from Mage but what if i need to pick data through my custom module, how i’ll explicitly mention if it is Mage module or my custom module. Will it automatically map getModule(‘abc/model’) ?
please explain,
thanks
thanks
this has really helped me with a section of my site. One thing i am still not sure on is how you retrieve a collection of products from the db for example i’d like to retrieve a random bunch of 6 products that are instock and sellable but have no idea how to go about it.
My only idea is to get an array of all product ids then have a php function randomly pick one out and get the details via a $cModel->load(); and write it, then repeat!!
Seems a bit long winded, but thanks for this article and keep up the good info, magento rocks but i agree it needs a bit more doc