• magento,  MAGENTO2

    Get product price and currency symbol in phtml page magento2 from product id

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
    
    $priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data');
    $b= 1234;
    $productd = $objectManager->get('Magento\Catalog\Model\Product')->load($b); 
    $regularPrice= $productd->getPrice();
    $specialPrice = $productd->getFinalPrice();
    <?php  echo $priceHelper->currency($specialPrice, true, false) ?> 
    // code for  currency with special price

  • magento,  MAGENTO2

    How to get product url from product id magento 2

     $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
     $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
    $b= 1232;  // the product id 
     $productd = $objectManager->get('Magento\Catalog\Model\Product')->load($b); 
     $sku = $productd->getSku();// getting Sku 
    $productData = $productRepository->get($sku);
    <a href="<?php echo $productData->getProductUrl(); ?>"> Show product </a>

  • magento,  MAGENTO2

    How to show product image from product id in phtml page magento 2

    The following code will show the product image from given product id

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $b=1232;  // product id 
    $productd = $objectManager->get('Magento\Catalog\Model\Product')->load($b);
    
    <div class="product-image"> 
        <img src="<?php echo $productd->getMediaConfig()->getMediaUrl($productd->getImage()); ?>" >
     </div> 

  • magento,  MAGENTO2

    How to get the SKU of product in phtml magento2 from given product Id.

    Through the help of Object Manager we can get SKU of the product if we have product id.

     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();  
     $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
     $b;
     $productd = $objectManager->get('Magento\Catalog\Model\Product')->load($b);  // product id 
     $sku = $productd->getSku();

  • magento,  MAGENTO2

    Magento 2 command on CMD

    php bin/magento deploy:mode:set developer

    this is to set the magento 2 to developer mode

    php bin/magento deploy:mode:set production

    this is to set the magento 2 to production mode

    phpphp bin/magento dev:template-hints:enable

    eg : http://localhost?templatehints=magento

    this is to set the magento 2 to template hint

  • magento

    magento 1.9 get parent category of category & attribute set name

    get the name of parent category

    $abc = Mage::registry(‘current_category’)->getName();
    $_category = Mage::getResourceModel(‘catalog/category_collection’)
    ->addFieldToFilter(‘name’, $abc)
    ->getFirstItem();
    $categoryId = $_category->getId();
    $categoryle = Mage::getModel(‘catalog/category’)->load($categoryId);
    $catnames = array();
    foreach ($categoryle->getParentCategories() as $parent) {
    $catnames[] = $parent->getName();
    }

    Get attribute set name of the product by id

    $productle = Mage::registry(‘current_product’);
    $prodid = $productle->getId();
    $attributeSetModel = Mage::getModel(“eav/entity_attribute_set”);
    $sess_product = Mage::getModel(‘catalog/product’)->load($prodid);
    $attributeSetModel->load($sess_product->getAttributeSetId());
    $attributeSetName = $attributeSetModel->getAttributeSetName();