Posts

Showing posts from August, 2017

Get Discount In Percentage of product.Magento2

Try This in List Page same way you can do it in detail page. <?php         $specialprice = $_product->getSpecialPrice();         $specialPriceFromDate = $_product->getSpecialFromDate();         $specialPriceToDate = $_product->getSpecialToDate();             $today = time();         $price = $_product->getPrice();         if($price){ $sale = round((($price-$specialprice)/$price)*100); }                                         if ($specialprice) {         if ($today >= strtotime($specialPriceFromDate) && $today <=                                             ...

Add Custom Wishlist in PHTML Magento2

  Add Custom Wishlist anywhere in Phtml  from here <a href="<?php echo $block->getUrl('wishlist', ['_secure' => true]);?>" img src="<?php echo $block->getViewFileUrl('images/wish_icon.jpg'); ?>" data-post='<?php  echo $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($_product) ?>' class="action towishlist" data-action="add-to-wishlist"><span>' . __('Add to Wish List') . '</span></a>                             

Getting product Image in PHTML in Magento2

        (1)  You have to load product to get thumbnail and url .     <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();     $product = $objectManager->create('Magento\Catalog\Model\Product')->load($_item->getProduct()->getId());     echo $product->getThumbnail();     echo  $product->getProductUrl(); ?>      (2) Get image url     $imagewidth=200;     $imageheight=200;     $imageHelper  = $objectManager->get('\Magento\Catalog\Helper\Image');     $image_url = $imageHelper->init($product, 'product_page_image_small')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl();     echo $image_url