magento add to wishlist message in product details page - magento

I want to show Wishlist Success Message in the product details page. I have change the redirection part. Now my page is redirecting to same page after added the product to wishlist. But I need to Show the message in same page. Kindly Help.. Thanks in advance. P.S.- I don't want to use ajax add to wishlist functionality.

The Magento Session models i.e. core/session, customer/session and catalog/session etc.
To add a message you can use "app\code\core\Mage\Wishlist\controllers\IndexController.php":
Action : addAction()
Find :
$session->addSuccess($message);
below write this code:
Mage::getSingleton('catalog/session')->addSuccess($message);
Then add error message :
Find :
catch (Mage_Core_Exception $e) {
$session->addError($this->__('An error occurred while adding item to wishlist: %s', $e->getMessage()));
}
catch (Exception $e) {
$session->addError($this->__('An error occurred while adding item to wishlist.'));
}
replace with below code :
catch (Mage_Core_Exception $e) {
$session->addError($this->__('An error occurred while adding item to wishlist: %s', $e->getMessage()));
$error_msg = $this->__('An error occurred while adding item to wishlist: %s', $e->getMessage());
Mage::getSingleton('catalog/session')->addError($error_msg);
} catch (Exception $e) {
$session->addError($this->__('An error occurred while adding item to wishlist.'));
Mage::getSingleton('catalog/session')->addError('An error occurred while adding item to wishlist.');
}
If "catalog/session" is not working please try "core/session".

Related

Laravel package whoops exception

In my Laravel package I have this code:
try {
$var_msg = "Exception example";
throw new InvalidNameException($var_msg);
}
catch (InvalidNameException $e) {
abort(403, $e->getMessage());
//report($e);Exception Log
}
The error is displayed as html error page. But, I'd like to report the error as an whoops error.
Take this code as reference.
$whoops = new \Whoops\Run();
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
// Set Whoops as the default error and exception handler used by PHP:
$whoops->register();
throw new \RuntimeException("Oopsie!");

Unable to catch error in laravel using try catch

I wrote a code to try and catch error.
I want that if the error occurs then laravel continues to the next one and i write the error in the error file as shown here.
Laravel's black page of error pops up which shows "ErrorException (E_WARNING) followed by the whole error on the left page and the programme is abruptly stopped.
Is there a way to skip the error notification which brings my whole code to a stop.
My attempt at coding to catch the error is here:
try {
$jsondata_car = (file_get_contents($urltofind_car));
} catch (Exception $e) {
$errorfile = fopen("errors", 'a');
fwrite($errorfile, $e - > getmessage().
"\n");
$failed_car = 9999999;
report($e);
return false;
}
Am I missing out something?
The error I get is here
file_get_contents(): failed to open stream:
HTTP request failed! HTTP/1.1 400 Bad Request
The error is shown on the line
$jsondata_car = (file_get_contents($urltofind_car));
The solution is here
Exception is used which should have contained a namespace.
The problem is that this does not throw up an error even though I had not written
Use Exception;
at the beginning.
As suggested by #simon R I made the rectification and it worked.
It is most likely still throwing the error because you haven't imported the Exception class
Ensure you either add
Use Exception;
to your class.
Alternative update your code to namespace it;
try {
$jsondata_car = (file_get_contents($urltofind_car));
} catch (\Exception $e) {
$errorfile = fopen("errors", 'a');
fwrite($errorfile, $e - > getmessage().
"\n");
$failed_car = 9999999;
report($e);
return false;
}

How to catch SqlIntegrityConstraint violation exception

I have a scenario where user submits an order for a fund and a security. And if he submits the another order with same fund and security DB throws back SqlIntegrityVoilationException with error code ora-00001.
But my question here is this exception is not getting caught under java.sql.sqlintegrityconstraintviolationexception. I am able to catch this under org.springframework.dao.DataIntegrityViolationException, but I am not able to retrieve the error code (to check for ora-00001).
Anybody has any ideas how to catch that exception and retrieve the error code to check so that I can put back a custom error message like "you cannot submit a dup order for same fund and security combination".
EDIT
catch (SQLException e) {
ex = e; inOrder.setActionMessage(ex.getMessage());
}
catch (DataIntegrityViolationException e) {
ex = e; inOrder.setActionMessage(ex.getMessage());
}

magento newsletter keeps returning an error even after email is saved

There was a problem with the subscription.
this is the message I get after I enter an email. When I go to the admin panel the email is added.
I would like it NOT to display this message. any suggestions please
The only place in Magento that error string occurs is in the following try/catch block
#File: app/code/core/Mage/Newsletter/controllers/SubscriberController.php
try {
//...snip!...
}
catch (Mage_Core_Exception $e) {
$session->addException($e, $this->__('There was a problem with the subscription: %s', $e->getMessage()));
}
catch (Exception $e) {
$session->addException($e, $this->__('There was a problem with the subscription.'));
}
Since you reported the error message as "There was a problem with the subscription.", that means the newsletter subscription code is throwing some sore of PHP exception, caught by the catch (Exception $e) { block. Magento does not output the messages from PHP exceptions. If I was in your position I'd temporarily change the exception handling code to include the error message
$session->addException($e, $this->__('There was a problem with the subscription. ' . $e->getMessage()));
This will let you track down the PHP error that's triggering your error message.
Per the comment below, the only place the "Cannot set standard header from addHeader()" exception error exists is
#File: lib/Zend/Mail.php
$prohibit = array('to', 'cc', 'bcc', 'from', 'subject',
'reply-to', 'return-path',
'date', 'message-id',
);
if (in_array(strtolower($name), $prohibit)) {
/**
* #see Zend_Mail_Exception
*/
#require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('Cannot set standard header from addHeader()');
}
$value = $this->_filterOther($value);
$value = $this->_encodeHeader($value);
$this->_storeHeader($name, $value, $append);
return $this;
My guess is somewhere in your system someone's added some custom code that tries to set one of the standard email headers via the addHeader method.

Magento stopped generating sitemap suddenly

Sitemap stopped generating suddenly.
Started displaying 'Unable to create XML sitemap.'
Please help
A quick fix to it .
Here I am using fishpig extension .
Observed that fishpig is overridding magento core sitemap controller .
So added the following code : /app/code/community/Fishpig/Wordpress/controllers/Adminhtml/SitemapController.php
Add this code before :
$this->_redirectReferer();
$id = $this->getRequest()->getParam('sitemap_id');
$sitemap = Mage::getModel('sitemap/sitemap');
/* #var $sitemap Mage_Sitemap_Model_Sitemap */
$sitemap->load($id);
// if sitemap record exists
if ($sitemap->getId()) {
try {
$sitemap->generateXml();
$this->_getSession()->addSuccess(
Mage::helper('sitemap')->__('The sitemap "%s" has been generated.', $sitemap->getSitemapFilename()));
}
catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
catch (Exception $e) {
$this->_getSession()->addException($e,
Mage::helper('sitemap')->__('Unable to generate the sitemap.'));
}
} else {
$this->_getSession()->addError(
Mage::helper('sitemap')->__('Unable to find a sitemap to generate.'));
}
Hope it helps someone experiencing with same issue .
Courtesy : lukecollymore

Resources