Example #1
0
 /**
  * Use this function which acts as Mage::dispatchEvent
  * but with validation where any observing entity can
  * change the isValid flag to tell the dispatcher to
  * act as if the event did not happen.
  * 
  * Callers should use this function in an if statement
  * which wraps code which depends on this event occuring.
  *
  * @param string $eventName
  * @param array $data key values of event attributes
  * @param unknown_type $isValid initial state of the dispatch
  * @return boolean
  */
 public function smartDispatch($eventName, array $data, $isValid = true)
 {
     $result = new Varien_Object(array('is_valid' => $isValid));
     // Append result object to data
     $data['result'] = $result;
     Mage::dispatchEvent($eventName, $data);
     return $result->getIsValid();
 }
Example #2
0
 /**
  * Get VAT class
  *
  * @param string $customerCountryCode
  * @param Varien_Object $vatValidationResult
  * @param Mage_Core_Model_Store|string|int|null $store
  * @return null|string
  */
 public function getCustomerVatClass($customerCountryCode, $vatValidationResult, $store = null)
 {
     $vatClass = null;
     $isVatNumberValid = $vatValidationResult->getIsValid();
     if (is_string($customerCountryCode) && !empty($customerCountryCode) && $customerCountryCode === Mage::helper('core')->getMerchantCountryCode($store) && $isVatNumberValid) {
         $vatClass = self::VAT_CLASS_DOMESTIC;
     } elseif ($isVatNumberValid) {
         $vatClass = self::VAT_CLASS_INTRA_UNION;
     } else {
         $vatClass = self::VAT_CLASS_INVALID;
     }
     if (!$vatValidationResult->getRequestSuccess()) {
         $vatClass = self::VAT_CLASS_ERROR;
     }
     return $vatClass;
 }