New answers tagged

0 votes

When it is good to use viewModel ? What is difference between viewModel and Block?

Short and simple based on the https://www.yireo.com/blog/2017-08-12-viewmodels-in-magento-2 Viewmodel allows you to disconnect your code from the Magento parents and focus on the data that you ...
user avatar
0 votes

Unable to override \Magento\Directory\Block\Data class-magento2

Try This Code <?php namespace VendoreName\ModuleName\Block; class Data extends \Magento\Directory\Block\Data { /** * @var \Magento\Framework\App\Cache\Type\Config */ protected $...
user avatar
  • 5,983
0 votes

How to get the product images by their role in Magento2 and display it to on frontend

Create a media type attribute for the product and assign it to the default attribute group. see the screenshot. Inside the code part where you want to featch OR display these images. <?php $...
user avatar
0 votes

How to get the product images by their role in Magento2 and display it to on frontend

You can get types of gallery images of a product by following code: $existingImage = $product->getMediaGalleryEntries(); foreach ($existingImage as $image) { $image->getTypes(); } ...
user avatar
0 votes

Magento 2 How to create CMS block with HTML content programmatically

Below code works for me. <?php namespace Custom\Module\Setup; use Magento\Cms\Model\BlockFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\...
user avatar
  • 1

Top 50 recent answers are included