daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function getVatValidationUserMessage($customerAddress, $customerGroupAutoAssignDisabled, $validationResult)
  2. {
  3.     $message = '';
  4.     $isError = true;
  5.     $customerVatClass = $this->getCustomerVatClass($customerAddress->getCountryId(), $validationResult);
  6.     $groupAutoAssignDisabled = Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMER_VIV_GROUP_AUTO_ASSIGN);
  7.  
  8.     $willChargeTaxMessage    = $this->__('You will be charged tax.');
  9.     $willNotChargeTaxMessage = $this->__('You will not be charged tax.');
  10.  
  11.     if ($validationResult->getIsValid()) {
  12.         $message = $this->__('Your VAT ID was successfully validated.');
  13.         $isError = false;
  14.  
  15.         if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) {
  16.             $message .= ' ' . ($customerVatClass == self::VAT_CLASS_DOMESTIC
  17.                 ? $willChargeTaxMessage
  18.                 : $willNotChargeTaxMessage);
  19.         }
  20.     } else if ($validationResult->getRequestSuccess()) {
  21.         $message = sprintf(
  22.             $this->__('The VAT ID entered (%s) is not a valid VAT ID.') . ' ',
  23.             $this->escapeHtml($customerAddress->getVatId())
  24.         );
  25.         if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) {
  26.             $message .= $willChargeTaxMessage;
  27.         }
  28.     }
  29.     else {
  30.         $contactUsMessage = sprintf($this->__('If you believe this is an error, please contact us at %s'),
  31.             Mage::getStoreConfig(self::XML_PATH_SUPPORT_EMAIL));
  32.  
  33.         $message = $this->__('Your Tax ID cannot be validated.') . ' '
  34.             . (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled
  35.                 ? $willChargeTaxMessage . ' ' : '')
  36.             . $contactUsMessage;
  37.     }
  38.  
  39.     $validationMessageEnvelope = new Varien_Object();
  40.     $validationMessageEnvelope->setMessage($message);
  41.     $validationMessageEnvelope->setIsError($isError);
  42.  
  43.     return $validationMessageEnvelope;
  44. }
  45.      
  46. if (!$validationMessage->getIsError()) {
  47.     Mage::getSingleton('customer/session')->addSuccess($validationMessage->getMessage());
  48. } else {
  49.     Mage::getSingleton('customer/session')->addError($validationMessage->getMessage());
  50. }
  51.      
  52. <block type="core/messages" name="global_messages" as="global_messages"/>
  53. <block type="core/messages" name="messages" as="messages"/>
  54.      
  55. /*
  56.  * @author: ..
  57.  * This class overrides the addMessage for customer.
  58.  * Because when BTW is validated, a message appears multiple times.
  59.  * With this rewrite we check if the message is not already added.
  60.  */
  61. class MYMODULE_Customer_Model_Session extends Mage_Customer_Model_Session
  62. {
  63.     /*
  64.      * Adding new message to message collection
  65.      *
  66.      * @param   Mage_Core_Model_Message_Abstract $message
  67.      * @return  Mage_Core_Model_Session_Abstract
  68.      */
  69.     public function addMessage(Mage_Core_Model_Message_Abstract $message)
  70.     {
  71.         // get all current messages
  72.         $sessionMessages = $this->getMessages()->getItems();
  73.         // loop thrue messages and find message with same text
  74.         $found = false;
  75.         foreach($sessionMessages as $sessionMessage) {
  76.             if ( $sessionMessage->getCode() == $message->getCode() ) {
  77.                 $found = true; // found message with same text
  78.             }
  79.         }
  80.         if ( !$found ) { // only add message if not already in session
  81.             $this->getMessages()->add($message);
  82.             Mage::dispatchEvent('core_session_abstract_add_message');
  83.         }
  84.         return $this;
  85.     }
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top