Posts

How to Add Product Name as Default Alt Text to All Product Images in Magento 2

 Steps to Add Product Name as Default Alt Text to All Product Images in Magento 2 Hello Magento Friends, Today I will be explaining How to Set Product Name as Default Alt Text to All Product Images in Magento 2. Alt text for product images informs the search engine what the image is about and helps index the product image when the user fires a query related to it. For Magento 2 stores, it is essential to give alt text to all the product images to aid in search engine rankings. Large stores can take advantage of Magento 2 Image Alt Tags Extension to automate the product image alternate text process and save time. You can also set the product name as the default alt text for all the product images in Magento 2. To do that, follow the below-given steps Contents [hide] 1 Steps to Set Product Name as Default Alt Text to All Product Images in Magento 2: 2 Conclusion: Steps to Set Product Name as Default Alt Text to All Product Images in Magento 2: Step 1: First, we need to create a “di.x...

How to Update Product Stock Programmatically in Magento 2

 Steps to Update Product Stock Programmatically in Magento 2: Step 1: We need to create a “Data.php” file inside our extension at the following path app\code\Vendor\Extension\Helper\ Now add the code as follows <?php namespace Vendor\Extension\Helper;   class Data extends \Magento\Framework\App\Helper\AbstractHelper {     protected $_productobj;     protected $_stockRegistry;       public function __construct(         \Magento\Framework\App\Helper\Context $context,         \Magento\Catalog\Model\Product $productobj,         \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,      ) {         $this->_productobj = $productobj;         $this->_stockRegistry = $stockRegistry;         parent::__construct($context);     }       public function updateProductStock($pr...

How to Get Estimated Shipping Methods using REST API in Magento 2

Steps to Get Estimated Shipping Methods using REST API in Magento 2: Step 1: Create the rootscript.php script file and add the below code <?php   $baseUrl = " http://yourdomain/"; // your magento base url //Customer Email id and Password set   $userData = array("username" => "test@gmail.com", "password" => "test@123");   $ch = curl_init($baseUrl."/rest/V1/integration/customer/token"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));   $token = curl_exec($ch);   $shippingData = array("address" =>   array("city" => "THOUSAND OAKS",        "company" => "Test Company",        "country_id...

How to Apply OR Conditions to Collection in Magento 2

 Steps to Apply OR Conditions to Collection in Magento 2: Step 1:  Apply OR condition for Magento 2 addAttributeToFilter collection protected  $_productCollection;   public function __construct(    \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection) {      $this->_productCollection = $productCollection; }      public function getProductCollection() {      $this->_productCollection->addAttributeToFilter(array(      array(           'attribute' => 'sku',           'like' => '24MB%’),           array(                'attribute' => 'type_id',                'eq' => 'simple')           ));        echo $this->_productCollection->getSelect(); } Output: SELECT...

How to Add Custom Text after Billing Address and Shipping Address in Admin Order View Page in magento2

 Steps to Add Custom Text after Billing Address and Shipping Address in Admin Order View Page in Magento 2:  Step 1:  First, we need to create a “sales_order_view.xml“ file inside our extension at the following path app\code\Vendor\Extension\view\adminhtml\layout\ Then add the below code <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">     <body>          <referenceBlock name="order_info">                 <action method="setTemplate">                     <argument name="template" translate="true" xsi:type="string">Vendor_Extension::order/info.phtml</argument>                 </action>         </...

How to Set Dynamic Email Subject in Magento 2

 Steps to Set Dynamic Email Subject in Magento 2: Step 1: Create an email template configuration file at the below path app\code\Vendor\Extension\etc\email_templates.xml  Then add the below code <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">     <template id="your_email_template_id" label="Label of your template file" file="email_file.html" type="html" module="Vendor_Extension" area="frontend"/> </config> Step 2: Now create an email template file at the following path app\code\Vendor\Extension\view\frontend\email\email_file.html Now add the below code snippet <!--@subject {{var subject|raw }}@--> <!--@vars {"var customerName":"Customer Name", "var customerEmail":"Customer Email", "var customerCom...

How to Automatically Generate CSV File on Every Order in Magento 2,

 Steps to Automatically Generate CSV File on Every Order in Magento 2: Step 1: Go to the below File Path app\code\Vendor\Extension\etc\events.xml Then, add the code as follows <?xml version='1.0'?> <config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='urn:magento:framework/Event/etc/events.xsd'>    <event name='sales_order_place_after'>         <observer                 name='sales_order_place_after'                 instance='Vendor\Extension\Observer\GenerateCSV'         />     </event> </config> Step 2: Next move to the below File Path app\code\Vendor\Extension\Observer\GenerateCSV.php Then add the below code snippet <?php   namespace Vendor\Extension\Observer;   use Magento\Framework\Event\ObserverInterface; use Magento\Framework\App\Filesystem\DirectoryL...