本文整理匯總了PHP中Varien_Event_Observer::getQuoteAddress方法的典型用法代碼示例。如果您正苦於以下問題:PHP Varien_Event_Observer::getQuoteAddress方法的具體用法?PHP Varien_Event_Observer::getQuoteAddress怎麽用?PHP Varien_Event_Observer::getQuoteAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Varien_Event_Observer
的用法示例。
在下文中一共展示了Varien_Event_Observer::getQuoteAddress方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: salesQuoteAddressSaveAfter
/**
* Validate vat id if given and assign tax class to quote shipping address
*
* @param Varien_Event_Observer $observer
*/
public function salesQuoteAddressSaveAfter(Varien_Event_Observer $observer)
{
/** @var Mage_Sales_Model_Quote_Address $quoteAddress */
$quoteAddress = $observer->getQuoteAddress();
if ($quoteAddress->getAddressType() != 'shipping') {
return;
}
$customer = $quoteAddress->getQuote()->getCustomer();
if (!Mage::helper('customer/address')->isVatValidationEnabled($customer->getStore()) || Mage::registry(self::VIV_PROCESSED_FLAG)) {
return;
}
try {
Mage::register(self::VIV_PROCESSED_FLAG, true);
/** @var $customerHelper Mage_Customer_Helper_Data */
$customerHelper = Mage::helper('customer');
if ($quoteAddress->getVatId() == '' || !Mage::helper('core')->isCountryInEU($quoteAddress->getCountry())) {
$defaultGroupId = $customerHelper->getDefaultCustomerGroupId($customer->getStore());
if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $defaultGroupId) {
$customerGroup = Mage::getModel('customer/group')->load($customer->getGroupId());
$quoteAddress->setTaxClassId($customerGroup->getTaxClassId());
$quoteAddress->save();
}
} else {
$result = $customerHelper->checkVatNumber($quoteAddress->getCountryId(), $quoteAddress->getVatId());
if (!$customer->getDisableAutoGroupChange()) {
$customerGroup = Mage::getModel('customer/group')->load($customer->getGroupId());
if ($result->getIsValid()) {
$quoteAddress->setTaxClassId($customerGroup->getTaxClassIdVatId());
} else {
$quoteAddress->setTaxClassId($customerGroup->getTaxClassId());
}
$quoteAddress->save();
}
if (!Mage::app()->getStore()->isAdmin()) {
$validationMessage = Mage::helper('customer')->getVatValidationUserMessage($quoteAddress, $customer->getDisableAutoGroupChange(), $result);
if (!$validationMessage->getIsError()) {
Mage::getSingleton('customer/session')->addSuccess($validationMessage->getMessage());
} else {
Mage::getSingleton('customer/session')->addError($validationMessage->getMessage());
}
}
}
} catch (Exception $e) {
Mage::register(self::VIV_PROCESSED_FLAG, false, true);
}
}
示例2: restoreQuoteCustomerGroupId
/**
* Restore initial customer group ID in quote if needed on collect_totals_after event of quote address
*
* @param Varien_Event_Observer $observer
*/
public function restoreQuoteCustomerGroupId($observer)
{
$quoteAddress = $observer->getQuoteAddress();
$configAddressType = Mage::helper('customer/address')->getTaxCalculationAddressType();
// Restore initial customer group ID in quote only if VAT is calculated based on shipping address
if ($quoteAddress->hasPrevQuoteCustomerGroupId() && $configAddressType == Mage_Customer_Model_Address_Abstract::TYPE_SHIPPING) {
$quoteAddress->getQuote()->setCustomerGroupId($quoteAddress->getPrevQuoteCustomerGroupId());
$quoteAddress->unsPrevQuoteCustomerGroupId();
}
}
示例3: update_shipping_rates
/**
* B4Requirement
* Updating the shipping rates with the discount provided by the AS400
*
* There is a special hook that we've had to hack the core and add, in order
* for this to work. Without the special hook described below we wont be able
* to adjust the rates before they are used by the rest of the system.
*
* Specially injected code into file
* C:\wamp\www\b4schools\app\code\core\Mage\Checkout\controllers\OnepageController.php
* on line 298, just before the $session gets cleared() in the successAction method
*
* // INJECTED FOR B4SCHOOLS
* Mage::dispatchEvent('checkout_onepage_controller_success_before_action', array('order_ids' => array($lastOrderId)));
* // --- END INJECTION
*
* We need to create our own hook event because the session gets cleared and
* we need catch the order_id before it's cleared and lost.
*
* @param Varien_Event_Observer $observer
*/
public function update_shipping_rates(Varien_Event_Observer $observer)
{
$address = $observer->getQuoteAddress();
$rates = $observer->getShippingRates();
try {
foreach ($rates as $rate) {
$price = $rate->getCost();
if (!$price) {
$price = $rate->getPrice();
}
$rate->setCost($price);
$rate->setPrice($price);
if ($rate->getCarrier() != 'ups') {
continue;
}
if ($rate->getMethod() != '03') {
continue;
}
// get the discount from the ERP
$discount = Mage::helper('idpas400')->getShippingDiscount($address->getData('postcode'), 'UPG', $address->getQuote());
Mage::getModel('customer/session')->setData('shippingDiscount', $discount);
Mage::getModel('customer/session')->setData('shippingRate', $price);
if ($discount === true) {
$shippingPrice = 0;
} else {
// adjusting shipping rate
$shippingPrice = 0;
$shippingPrice = $shippingPrice + $price;
$shippingPrice = $shippingPrice - $discount;
if ($shippingPrice < 0) {
$shippingPrice = 0;
}
}
$rate->setPrice($shippingPrice);
$rate->setCost($shippingPrice);
}
} catch (Exception $e) {
Mage::logException($e);
}
}