Tuesday 17 April 2018

How to get current Currency and symbol in PHTML File in magento 2 ?


    <?php
        $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $currencysymbol = $_objectManager->get('Magento\Store\Model\StoreManagerInterface');
        $currencyCode = $currencysymbol->getStore()->getCurrentCurrencyCode();
        $currency = $_objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->load($currencyCode);
        $currencySymbol = $currency->getCurrencySymbol();
    ?>

Magento 2 How can I show custom options on product list page?



<?php
     $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();

    $customOptions = $_objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($_product);
    $optStr = "";
    foreach($customOptions as $optionKey => $optionVal):
        $optStr .= "<div class='custom-options'><label>".$optionVal->getTitle()." </label>";
            $optStr .= "<select name='options[".$optionVal->getId()."]'>";
            foreach($optionVal->getValues() as $valuesKey => $valuesVal) {
            $optStr .= "<option value='".$valuesVal->getId()."'>".$valuesVal->getTitle()."</option>";
                }

        $optStr .= "</select></div>";
    endforeach;
       echo($optStr );

?>

How to select option onchange url redirection

How to select option onchange url redirection:

<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option value="" selected>---Select---</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.google.com">Google</option>
</select>

Monday 9 April 2018

How to display percentage of discount on product list and product view page in magento1.9?

How to display percentage of discount on product list and product view page in magento1.9?

app/design/frontend/yourpackage/yourtheme/template/catalog/product/price.phtml

Find: (line 397)

<?php endif; /* if ($_finalPrice == $_price): */ ?>

Past above it:

<?php // Discount percents output start ?>
    <?php if($_finalPrice < $_price): ?>
    <?php $_savePercent = 100 - round(($_finalPrice / $_price)*100); ?>
        <p class="special-price yousave">
            <span class="label"><?php echo $this->__('You Save:') ?></span>
            <span class="price">
                <?php echo $_savePercent; ?>%
            </span>
        </p>
    <?php endif; ?>
<?php // Discount percent output end ?>

How to set min height by Jquery

$j(document).ready(function(){
$j('.progrdCol').each(function() {
        startListHeight($j('.progrdCol > .productRap'));
    });
});

function startListHeight($tag) {
 
    function setHeight(s) {
        var max = 0;
        s.each(function() {
            var h = $j(this).height();           
            max = Math.max(max, h);
        }).height('').height(max);
    }
 
    $j(window).on('ready load resize', setHeight($tag));
}

Friday 6 April 2018

How to Add Social Sharing Links for a Product in Magento 2

How to Add Social Sharing Links for a Product in Magento 2


<div class="wdm-social-icons" data-role="wdm-social-icons">

<!-- FACEBOOK -->
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode($_product->getProductUrl());?>&t=<?php echo urlencode($_product->getName())?>" onclick='javascript:window.open(this.href,"","width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes");return false' title="Share on FaceBook">
<img src="<?php echo $this->getViewFileUrl('images/fb-med.png'); ?>" alt="FaceBook" width="5%">
</a>

<!-- TWITTER -->
<a href="http://twitter.com/home/?status=<?php echo urlencode($_product->getProductUrl());?>(<?php echo urlencode($_product->getName())?>)" onclick='javascript:window.open(this.href,"","width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes");return false' title="Share on Twitter">
<img src="<?php echo $this->getViewFileUrl('images/tw.png'); ?>" alt="Twitter" width="5%">
</a>

</div>

Tuesday 3 April 2018

How to Increase / decrease qty directly on cart page in magento 1.9

How to Increase / decrease qty directly on cart page in magento 1.9

First, I give an id (form-update-post) to the form of the cart page : (app/design/frontend/rwd/default/template/checkout/cart.phtml)

<form action="<?php echo $this->getFormActionUrl() ?>" method="post" id="form-update-post">

    Then, I add two buttons, and I add an id to the qty field of the items : (checkout/cart/item/default.phtml)

<a href="javascript:decreaseQty(<?php echo $_item->getId() ?>)" class="decrement_qty"><span class="fa fa-minus">-</span></a>
<input id="quantity-item-<?php echo $_item->getId() ?>" name="cart[<?php echo $_item->getId() ?>][qty]"
   data-cart-item-id="<?php echo $this->jsQuoteEscape($_item->getSku()) ?>"
   value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" />
<a href="javascript:increaseQty(<?php echo $_item->getId() ?>)" class="increment_qty"><span class="fa fa-plus">+</span></a>

The last step is to add those Javascript functions in the cart page : (checkout/cart.phtml)

<script type="text/javascript">
    function increaseQty(id){
        var input = jQuery("#quantity-item-"+id);
        input.val(parseInt(input.val())+1);
        var form = jQuery("#form-update-post");
        if(form !== undefined){
            form.submit();
        }
    }

    function decreaseQty(id){
        var input = jQuery("#quantity-item-"+id);
        if(input.val() > 1){
            input.val(input.val()-1);
        }
        var form = jQuery("#form-update-post");
        if(form !== undefined){
            form.submit();
        }
    }
</script>

Increment and decrement qty button on shopping cart page in magento 1.9

Increment and decrement qty button on shopping cart page in magento 1.9

        <div class="qty-wrapper">
            <label for="qty"><?php echo $this->__('Quantity:') ?></label>
            <div class="qty-box">
                 <?php if(!$_product->isGrouped()): ?>
                    <a class="minus" id="<?php echo $_product->getId() . "minus" ?>" href="javascript:void(0);">-</a>
                    <input type="text" readonly="true" name="qty" id="qty<?php echo $_product->getId() ?>" maxlength="12" value="<?php echo ($_product->getStockItem()->getMinSaleQty() ? $_product->getStockItem()->getMinSaleQty() : 1) ?>" />
                    <a class="plus" id="<?php echo $_product->getId() . "plus" ?>"  href="javascript:void(0);">+</a>
                <?php endif; ?>
            </div>
        </div>


----------------------------------------------------
<script type="text/javascript">
$j(document).ready(function() {
    $j(".minus").click(function() {
        var id = this.id;
        var value = $j('#' + id).next('input').val();
        var fieldID = $j(this).next('input').attr("id");
        if (value > 1) {
            value = value - 1;
            $j('#' + fieldID).val(value);
        }
    });
    $j(".plus").click(function() {
        var id = this.id;
        var value = $j('#' + id).prev('input').val();
        var fieldID = $j(this).prev('input').attr("id");
        ++value;
        $j('#' + fieldID).val(value);
    });
});
</script>