For example, the following action will add a message which will be inserted into the page:
-When addtocart button is clicked, it will display a message saying the product was added successful or not.
The code is in app/code/core/Mage/Checkout/controllers/CartControllers.php
$message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
$this->_getSession()->addSuccess($message);
-When a product review is submitted, there will be a message saying the review has been accepted for moderation.
The code is in app/code/core/Mage/Review/controllers/ProductController.php
$session->addSuccess($this->__('Your review has been accepted for moderation.'));
The above two are just examples, there are more other similar messages which are display on certain actions.
I know how to override it, change or remove the message. For the addtocart message, it can also be turned off by going to the Admin Panel.
I believe there is a better way to modify those messages than create a module and overriding the function just for modifying the message or remove it.
Does anyone know any better ways to modify or remove those addSuccess messages?
How can we modify or remove those messages after addSuccess() function is already called and the messages are added?
Of course there's a better way ;D
Take a look into your app/locale/en_US folder (or whichever language you want to edit). There you'll find a series of CSV files with translations.
Every time you see echo $this->_('Something Here'); it means there is a translation in these CSV files. This depends on the current namespace, so for Checkout messages, you'd want to look in Mage_Checkout.csv first.
Open with your favorite text editor and look for something like this:
%s was added to your shopping cart.,%s was added to your shopping cart.
Now, change the line AFTER the comma to what you would like it to be:
%s was added to your shopping cart.,We just added %s to your cart!
Alternatively, you can make it blank by just removing everything after the comma:
%s was added to your shopping cart.,
The %s denotes the variable used, which is passed as the second parameter in the _() function.
This should remove all success or error messages from your session.
$this->_getSession()->getMessages(true);
More specifically, you can use the following to remove messages from core and customer session respectively:
Mage::getSingleton('core/session')->getMessages(true);
Mage::getSingleton('customer/session')->getMessages(true);
For the addtocart message, it can also be turned off by going to the Admin Panel.
As #s-hunter said the above quote, can any one tell where to find the setting to turn it off.
Related
I have an observer watching the event sales_quote_item_set_product. In it, i am checking some conditions to make sure the item is still available. If it is not, i run this code:
Mage::helper('checkout/cart')->getCart()->removeItem($item->getId())->save();
Mage::getSingleton('message/session')->addError($item->getName() . ' is no longer available.');
The problem I'm having is if an item becomes unavailable and a guest is on a product view page, the cart says the item is in the cart, but the total for the cart is updated to reflect the product being removed. Also the error message is not displayed. If you go to another page or refresh the product view page the error message will display and the number of items in the cart will be correct.
So my thought is i need to run this code earlier in the execution cycle, but i have no idea what event i should be observing, or if i shouldn't be using an observer at all. I tried using sales_quote_load_after, but that caused a recursion error somehow. Can anyone tell me when/where i should run this code?
Another wild thought is could it be because i'm using database sessions instead of the file system?
The problem was that the error was being added after the messages block was rendered. I fixed it by adding a redirect to the cart page after the error was added.
$request = Mage::app()->getRequest();
if($request->getModuleName() != 'checkout' && $request->getControllerName() != 'cart' && $request->getActionName() != 'index') {
Mage::app()->getResponse()->setRedirect(Mage::getModel('core/url')->getUrl('checkout/cart/index'))
->sendResponse();
exit;
}
You didn't mention it, but this sounds like you're running code during an AJAX request. When you say
Mage::getSingleton('message/session')->addError($item->getName() . ' is no longer available.');
You're adding an error to Magento's session object. Every time a Magento page renders, it checks the session object for errors, and displays them all. This allows multiple developers to add multiple errors to the session, redirect Magento back to the original form.
This doesn't work during an ajax request, because (typically) the rendering process is skipped in lieu of a JSON object or simple, errorless HTML chunk being rendered (leaving the errors in the session).
Knowing what the full request cycle looks like (what's ajax, what's not) would help someone come up with a more concrete answer to your question.
Is there a way to REQUIRE a PayPal dropdown to be answered? Currently, my choices are 1. Select One, 2. Satchel Brown, and 3. Midnight Black. If I skip it, it accepts "Select One" as the option. What to do? Leave the first option blank? I don't want to use a default answer.
Are you using a custom button (code generated using a form) or a paypal supported button that you generated the code for in paypal?
If you are using a paypal custom created button, create a confirmation page and have it post the users choice to there. Then, using php, check to see that the users choice is one of the valid options. If it is not, then simply use the header('Location: http://www.MyWebsiteHere.com/Wherever.php?&error=Unselected') to send them back to the page and add a error message so if(isset($_GET['error'])), then echo $correspondingErrorMessage. Very simple thing if you do it like this.
I want to change to button actions in the Magento admin orders section, and after looking at a lot of posts on here I can not find an answer that fulfills my question:
Question:
I want to be able to click the print invoice button on the order and have it automatically change to shipped status and when I add shipping to the order with a tracking number and click submit I would like that status to change to shipped.. and I was wondering how this could be done?
In summary:
status changed to shipped - when invoice is printed
status changed to complete - when order is shipped
I assume I would start in editing this section: app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
To change the status of an order the instruction is :
$order->setState('your state', true);
Ex. :
$order->setState('complete', true);
To have what you want you should edit the controller called when printing the invoice or creating the shipment. It's :
/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php in the printAction() method just after the line :
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
For the printing of invoice and
/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php in the saveAction() method just after the line :
$shipment->register();
But editing Controller is the most simple but the worst solution. If you know well Magento and php you could do this through Model or through events.
Best Regards,
I'm trying to get Magento to redirect after a customer clicks the 'Add to Cart' button over to the category page, which I have done with no problem (after a little bit of searching around, of course) by using a hidden field with the name of "return_url". This part works perfectly, and the item is added to the cart, and the user is redirected back to the category page. Once here, no matter what I've tried I cannot get the message block to show the success (or error) message. Here is my most recent code attempt (in view.phtml):
$messages=Mage::getSingleton("checkout/session")->getMessages();
echo $this->getLayout()->createBlock("core/messages")->setMessages($messages)->getGroupedHtml();
Thanks!
Have you tried more simple addSuccess/addError/addNotice functions?
Mage::getSingleton('core/session')->addError(Mage::helper('core')->__('An error'));
Mage::getSingleton('core/session')->addSuccess(Mage::helper('core')->__('A success'));
Mage::getSingleton('core/session')->addNotice(Mage::helper('core')->__('A notice'));
You can add a message to different session model types like "catalog", "customer", "checkout" or simple "core".
Same as:
Mage::getSingleton('catalog/session')
Mage::getSingleton('customer/session')
Mage::getSingleton('checkout/session')
Mage::getSingleton('core/session')
In your case, the customer session messages are not initialized in the category controller. Take a look at
\Mage_Catalog_CategoryController::viewAction
The end of the function should look like this:
$this->_initLayoutMessages('catalog/session');
$this->_initLayoutMessages('checkout/session');
$this->renderLayout();
To display the messages from "customer/session", this area must look like this:
$this->_initLayoutMessages('catalog/session');
$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('checkout/session');
$this->renderLayout();
I've been reading a lot about this problem but I get nothing that suggests a way out.
I am working with version 1.3.2.4 and after creating a bundle product, Magento displays it as price as zero, but gives the "current composition" as the correct value.
alt text http://www.balexandre.com/temp/2009-10-13_2158.png
I already tried to refresh the cache, rebuild the catalog index, and nothing works...
Then I went deep and navigated into the price.phtml template under
template/bundle/catalog/product/view/
and tried to invoke the same method that is showing correctly the value, bu that as well, return zero.
I did notice that Magento has this javascript method
bundle.reloadPrice();
right after and if invoked I do get the correct price... I can try, using jQuery (or Prototype as Magento uses by default) change the value, but I was trying to this right...
Any other ideas?
Had the same problem.
price showed as 0.00.
you have to edit your price-attribute -> show in product-listing: yes
for the product page I'm using this as a work around:
executing this jQuery code:
// hide "Price as configured" text
jQuery(".price-as-configured span:first").hide();
// hide the 0,00 price
jQuery(".price-box-bundle").hide();
// hide the 2nd price (not in image)
jQuery(".product-options-bottom .price-box").hide();
will pass this:
alt text http://www.balexandre.com/temp/2009-10-13_2338.png
into this:
alt text http://www.balexandre.com/temp/2009-10-13_2339.png
In the product grid list I'm using this code to hide the price/button and add to wish list links
// GRID
jQuery("#products-grid-table .price-box").hide();
jQuery("#products-grid-table .button").hide();
jQuery("#products-grid-table .add-to-links").hide();
// LIST
jQuery("#products-list .price-box").hide();
jQuery("#products-list .button").hide();
jQuery("#products-list .add-to-links").hide();
and it will pass this
alt text http://www.balexandre.com/temp/2009-10-14_0005.png
into this
alt text http://www.balexandre.com/temp/2009-10-14_0006.png
I hope it helps someone ...
you can use my magento module: https://github.com/head82/KH_ExtendedBundlePrice tested with magento 1.7