daily pastebin goal
92%
SHARE
TWEET

Untitled

a guest May 16th, 2018 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. protected $_product;
  2.  
  3. public function __construct(
  4.     ...      
  5.     MagentoCatalogModelProductFactory $productFactory,
  6.     ...
  7. ) {
  8.     $this->productFactory = $productFactory;
  9. }
  10.  
  11. public function getPriceById($id)
  12. {
  13.     //$id = '21'; //Product ID
  14.     $product = $this->productFactory->create();
  15.     $productPriceById = $product->load($id);
  16.     return $productPriceById;
  17. }
  18.  
  19. public function getPriceBySku($sku)
  20. {  
  21.     //$sku = 'testing'; //Product sku
  22.     $product = $this->productFactory->create();
  23.     $productPriceBySku = $product->loadByAttribute('sku', $sku);
  24.     return $productPriceBySku;
  25. }
  26.    
  27. <?php
  28.  
  29.     $productId = 8 //product id
  30.  
  31.     $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  32.     $productRepository  = $objectManager->get('MagentoCatalogApiProductRepositoryInterface');
  33.     $product = $productRepository->getById($productId);
  34.  
  35.  
  36.     $abstractProductBlock = $block->getLayout()->createBlock('MagentoCatalogBlockProductAbstractProduct');    
  37.     echo $price =$abstractProductBlock->getProductPrice($product);
  38.  
  39.  
  40. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top