Skip to content

Instantly share code, notes, and snippets.

@philwinkle
Created April 14, 2013 00:32
Show Gist options
  • Save philwinkle/5380784 to your computer and use it in GitHub Desktop.
Save philwinkle/5380784 to your computer and use it in GitHub Desktop.
Mage_Autoquote
<?xml version="1.0"?>
<!--
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Checkout
* @copyright Copyright (c) 2004-2007 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config>
<global>
<models>
<mageautoquote>
<class>Mage_Autoquote_Model</class>
</mageautoquote>
</models>
<cache>
<types>
<checkout_quote><label>Shopping Cart data</label></checkout_quote>
</types>
</cache>
</global>
<frontend>
<events>
<checkout_cart_product_add_after>
<observers>
<mage_autoquote_observer>
<type>singleton</type>
<class>mageautoquote/observer</class>
<method>add_default_shipping</method>
</mage_autoquote_observer>
</observers>
</checkout_cart_product_add_after>
</events>
</frontend>
<adminhtml>
<translate>
<modules>
<Mage_Autoquote>
<files>
<default>Mage_Autoquote.csv</default>
</files>
</Mage_Autoquote>
</modules>
</translate>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<autoquote>
<title>Auto Quote</title>
</autoquote>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<default>
<autoquote>
<settings>
<enabled>0</enabled>
<method>flatrate_flatrate</method>
</settings>
</autoquote>
</default>
</config>
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Questions
* @copyright Copyright (c) 2004-2007 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Questions base helper
*
* @category Mage
* @package Mage_Questions
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Autoquote_Helper_Data extends Mage_Core_Helper_Abstract
{
const XML_PATH_ENABLED = 'autoquote/settings/enabled';
const XML_PATH_COUNTRY = 'autoquote/origin/country_id';
const XML_PATH_REGION = 'autoquote/origin/region_id';
const XML_PATH_POSTCODE = 'autoquote/origin/postcode';
const XML_PATH_CITY = 'autoquote/origin/city';
const XML_PATH_MEATHOD = 'autoquote/settings/method';
public function isEnabled()
{
return Mage::getStoreConfig( self::XML_PATH_ENABLED );
}
public function isCountry_id()
{
return Mage::getStoreConfig( self::XML_PATH_COUNTRY );
}
public function isRegion_id()
{
return Mage::getStoreConfig( self::XML_PATH_REGION );
}
public function isPostcode()
{
return Mage::getStoreConfig( self::XML_PATH_POSTCODE );
}
public function isCity()
{
return Mage::getStoreConfig( self::XML_PATH_CITY );
}
public function isMethod()
{
return Mage::getStoreConfig( self::XML_PATH_MEATHOD );
}
}
.
└── app
├── code
│   └── community
│   └── Mage
│   └── Autoquote
│   ├── Helper
│   │   └── Data.php
│   ├── Model
│   │   └── Observer.php
│   └── etc
│   ├── config.xml
│   └── system.xml
└── etc
└── modules
└── Mage_Autoquote.xml
10 directories, 5 files
<?xml version="1.0"?>
<config>
<modules>
<Mage_Autoquote>
<active>true</active>
<codePool>community</codePool>
</Mage_Autoquote>
</modules>
</config>
<?php
class Mage_Autoquote_Model_Observer
{
/**
*
* @param Varien_Event_Observer $observer
* @return Xyz_Catalog_Model_Price_Observer
*/
public function add_default_shipping($observer)
{
if (Mage::getStoreConfig('autoquote/settings/enabled'))
{
$country = Mage::getStoreConfig('autoquote/origin/country_id');
$postcode = Mage::getStoreConfig('autoquote/origin/postcode');
$city = Mage::getStoreConfig('autoquote/origin/city');
$regionId = Mage::getStoreConfig('autoquote/origin/region_id');
$region = '';
$code = Mage::getStoreConfig('autoquote/settings/method');
try {
if (!empty($code)) {
$shippingAddress = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
$groups = $shippingAddress->getGroupedAllShippingRates();
if(!$shippingAddress->getShippingMethod())
{
$shippingAddress
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setShippingMethod($code)
->setCollectShippingRates(true);
Mage::getSingleton('checkout/session')->getQuote()->save();
Mage::getSingleton('checkout/session')->getQuote()->getPayment()->setMethod('');
Mage::getSingleton('checkout/session')->getQuote()->save();
}
} else {
Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setCollectShippingRates(true);
Mage::getSingleton('checkout/session')->getQuote()->save();
}
Mage::getSingleton('checkout/session')->resetCheckout();
}
catch (Mage_Core_Exception $e) {
Mage::getSingleton('checkout/session')->addError($e->getMessage());
}
catch (Exception $e) {
Mage::getSingleton('checkout/session')->addException(
$e,
Mage::helper('checkout')->__('Load customer quote error')
);
}
return $this;
}
}
public function getQuote()
{
if (empty($this->_quote)) {
$this->_quote = Mage::getSingleton('checkout/session')->getQuote();
}
return $this->_quote;
}
}
<?xml version="1.0"?>
<!--
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Shipping
* @copyright Copyright (c) 2004-2007 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config>
<sections>
<autoquote translate="label" module="autoquote">
<label>Auto Quote</label>
<tab>sales</tab>
<frontend_type>text</frontend_type>
<sort_order>314</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<groups>
<settings translate="label">
<label>Settings</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<enabled translate="label">
<label>Enable Auto Quote</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>8</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</enabled>
<method translate="label">
<label>Default Method</label>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</method>
</fields>
</settings>
<origin translate="label">
<label>Quote Destination</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<country_id translate="label">
<label>Country</label>
<frontend_type>select</frontend_type>
<frontend_class>countries</frontend_class>
<source_model>adminhtml/system_config_source_country</source_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</country_id>
<region_id translate="label">
<label>Region/State</label>
<frontend_type>text</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</region_id>
<postcode translate="label">
<label>ZIP/Postal Code</label>
<frontend_type>text</frontend_type>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</postcode>
<city translate="label">
<label>City</label>
<frontend_type>text</frontend_type>
<sort_order>40</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</city>
</fields>
</origin>
</groups>
</autoquote>
</sections>
</config>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment