Giter Club home page Giter Club logo

mageprofis_inclexcltaxswitch's Introduction

MageProfis_InclExclTaxSwitch

Switch frontend prices incl/excl tax with a URL parameter. (Session based)
Incl. Tax: example.com/demo.html?brutto
Excl. Tax: example.com/demo.html?netto

Default state will be set here:
Magento Admin > System > Configuration > Tax > Display Price > Catalog prices include tax

Compatible with

  • FireGento_MageSetup
  • FireGento_GermanSetup

Frontend Switch Example:

<?php $priceDisplayType = Mage::getModel('tax/config')->getPriceDisplayType() ?>
<div class="grid-full">
    <div class="inclexcltaxswitch <?php echo $priceDisplayType==2 ? 'incl' : 'excl' ?>">
        <div class="inclexcltaxswitch-label">
            <?php echo $this->__('Alle Preise') ?>
        </div>
        <div class="inclexcltaxswitch-switch">
            <a href="#" rel="nofollow" onclick="window.location.href = updateUrlParameter(window.location.href, 'netto', 'brutto'); return false;" class="<?php echo $priceDisplayType==1 ? 'active' : '' ?>"><?php echo $this->__('zzgl. Ust.') ?></a>
        </div>
        <div class="inclexcltaxswitch-switch">
            <a href="#" rel="nofollow" onclick="window.location.href = updateUrlParameter(window.location.href, 'brutto', 'netto'); return false;" class="<?php echo $priceDisplayType==2 ? 'active' : '' ?>"><?php echo $this->__('incl. Ust.') ?></a>
        </div>
    </div>
    <script>
        function updateUrlParameter(uri, key, removekey) {
            uri = uri.replace("?"+removekey+"=", "?");
            uri = uri.replace("?"+removekey+"", "?");
            uri = uri.replace("&"+removekey+"=", "");
            uri = uri.replace("&"+removekey+"", "");
            uri = uri.replace("?"+key+"=", "?");
            uri = uri.replace("?"+key+"", "?");
            uri = uri.replace("&"+key+"=", "");
            uri = uri.replace("&"+key+"", "");
            // remove the hash part before operating on the uri
            var i = uri.indexOf('#');
            var hash = i === -1 ? ''  : uri.substr(i);
                 uri = i === -1 ? uri : uri.substr(0, i);

            var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
            var separator = uri.indexOf('?') !== -1 ? "&" : "?";
            if (uri.match(re)) {
                uri = uri.replace(re, '$1' + key + "=" + value + '$2');
            } else {
                uri = uri + separator + key;
            }
            uri = uri.replace("?&", "?");
            return uri + hash;  // finally append the hash as well
        }
    </script>
</div>

Todo

  • Optimizing JavaScript code
  • On/Off System Configuration

mageprofis_inclexcltaxswitch's People

Contributors

devertnet avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.