Post by JazzBlueRT » Thu Dec 30, 2021 10:40 pm

I have the Avalara tax tables downloaded into a table. I have a new function that integrates them into the shipping address. On past upgrades I just diffed the files and copied my function over but want to do it correctly without changing core files this time.

In system/library/cart/tax.php, I want to replace

Code: Select all

public function setShippingAddress
with an entirely new function of the same name.

I have

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Avalara Tax Tables</name>
    <code>What Goes here</code>
    <version>1.0</version>
    <author>Me</author>
    <link>https://retroactives.com</link>
    <file path="system/library/cart/tax.php">
        <operation>
            <search><![CDATA[public function setShippingAddress($country_id, $zone_id) {
		$tax_query = $this->db->query("SELECT tr1.tax_class_id, tr2.tax_rate_id, tr2.name, tr2.rate, tr2.type, tr1.priority FROM " . DB_PREFIX . "tax_rule tr1 LEFT JOIN " . DB_PREFIX . "tax_rate tr2 ON (tr1.tax_rate_id = tr2.tax_rate_id) INNER JOIN " . DB_PREFIX . "tax_rate_to_customer_group tr2cg ON (tr2.tax_rate_id = tr2cg.tax_rate_id) LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr2.geo_zone_id = z2gz.geo_zone_id) LEFT JOIN " . DB_PREFIX . "geo_zone gz ON (tr2.geo_zone_id = gz.geo_zone_id) WHERE tr1.based = 'shipping' AND tr2cg.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND z2gz.country_id = '" . (int)$country_id . "' AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int)$zone_id . "') ORDER BY tr1.priority ASC");

		foreach ($tax_query->rows as $result) {
			$this->tax_rates[$result['tax_class_id']][$result['tax_rate_id']] = array(
				'tax_rate_id' => $result['tax_rate_id'],
				'name'        => $result['name'],
				'rate'        => $result['rate'],
				'type'        => $result['type'],
				'priority'    => $result['priority']
			);
		}
	}]]></search>
            <add position="replace"><![CDATA[public function setShippingAddress($country_id, $zone_id) {
        if (!empty($this->session->data['shipping_address']['postcode'])) {
            $post_code = (int) $this->session->data['shipping_address']['postcode'];
            $query = "SELECT tr1.tax_class_id, tr2.tax_rate_id, tr2.name, 
                (select EstimatedCombinedRate from " . DB_PREFIX . "zip_tax where ZipCode=" . $post_code . ") as rateOverride, tr2.type, tr1.priority FROM " . DB_PREFIX . "tax_rule tr1 LEFT JOIN " . DB_PREFIX . "tax_rate tr2 ON (tr1.tax_rate_id = tr2.tax_rate_id) INNER JOIN " . DB_PREFIX . "tax_rate_to_customer_group tr2cg ON (tr2.tax_rate_id = tr2cg.tax_rate_id) LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr2.geo_zone_id = z2gz.geo_zone_id) LEFT JOIN " . DB_PREFIX . "geo_zone gz ON (tr2.geo_zone_id = gz.geo_zone_id) WHERE tr1.based = 'shipping' AND tr2cg.customer_group_id = '" . (int) $this->config->get('config_customer_group_id') . "' AND z2gz.country_id = '" . (int) $country_id . "' AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int) $zone_id . "') ORDER BY tr1.priority ASC";
            $tax_query = $this->db->query($query);
            foreach ($tax_query->rows as $result) {
                $this->tax_rates[$result['tax_class_id']][$result['tax_rate_id']] = array(
                    'tax_rate_id' => $result['tax_rate_id'],
                    'name' => $result['name'],
                    'rate' => $result['rateOverride'] * 100,
                    'type' => $result['type'],
                    'priority' => $result['priority']
                );
            }
        } else {
            $tax_query = $this->db->query("SELECT tr1.tax_class_id, tr2.tax_rate_id, tr2.name, tr2.rate, tr2.type, tr1.priority FROM " . DB_PREFIX . "tax_rule tr1 LEFT JOIN " . DB_PREFIX . "tax_rate tr2 ON (tr1.tax_rate_id = tr2.tax_rate_id) INNER JOIN " . DB_PREFIX . "tax_rate_to_customer_group tr2cg ON (tr2.tax_rate_id = tr2cg.tax_rate_id) LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr2.geo_zone_id = z2gz.geo_zone_id) LEFT JOIN " . DB_PREFIX . "geo_zone gz ON (tr2.geo_zone_id = gz.geo_zone_id) WHERE tr1.based = 'shipping' AND tr2cg.customer_group_id = '" . (int) $this->config->get('config_customer_group_id') . "' AND z2gz.country_id = '" . (int) $country_id . "' AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int) $zone_id . "') ORDER BY tr1.priority ASC");
            foreach ($tax_query->rows as $result) {
                $this->tax_rates[$result['tax_class_id']][$result['tax_rate_id']] = array(
                    'tax_rate_id' => $result['tax_rate_id'],
                    'name' => $result['name'],
                    'rate' => $result['rate'],
                    'type' => $result['type'],
                    'priority' => $result['priority']
                );
            }
        }
    } ]]></add>
        </operation>
    </file>  
</modification>

And save as:
useavalarataxtables.ocmod.xml

Is this correct?

------------------------------------------
Retro gifts, toys, games and accessories
https://www.retroactives.com/


User avatar
New member

Posts

Joined
Mon Nov 06, 2017 1:34 am

Post by xxvirusxx » Fri Dec 31, 2021 12:49 am

JazzBlueRT wrote:
Thu Dec 30, 2021 10:40 pm
And save as:
useavalarataxtables.ocmod.xml

Is this correct?
Yes and No

Yes for 2.x.x.x version No for 3.x.x.x version

My Converted Modules | Opencart Upgrade Service | Free Dashboard Maps | Buy me a beer | My Custom OC 3.0.3.8


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România
Who is online

Users browsing this forum: No registered users and 4 guests