Posts

How to Add URL Rewrite Programmatically in Magento 2

 <?php namespace Vendor\Extension\Controller; use Magento\Framework\App\Action\Context; class CustomController {      protected $urlRewriteFactory;      public function __construct(             Context $context,             \Magento\UrlRewrite\Model\UrlRewriteFactory $urlRewriteFactory)      {          $this->urlRewriteFactory = $urlRewriteFactory;          parent::__construct($context);      }      public function execute()       {         $urlRewrite = $this->urlRewriteFactory->create();        /*if you want to rewrite url for “custom” set entity type*/        $urlRewrite->setEntityType('custom');        /*set current store ID */        $urlRewrite->setStore...

Removing Customer Account Navigation Links in Magento 2: A Step-by-Step Guide

  <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body>    <!-- Remove unwanted account navigation links -->    <!-- Put this file in: app/design/frontend/[Namespace]/[Theme]/Magento_Customer/layout/customer_account.xml -->    <!-- Store credit -->    <referenceBlock name="customer-account-navigation-customer-balance-link" remove="true"/>    <!-- Downloadable product link -->    <referenceBlock name="customer-account-navigation-downloadable-products-link" remove="true"/>    <!-- Subscription link -->    <referenceBlock name="customer-account-navigation-newsletter-subscriptions-link" remove="true"/>    <!-- Billing agreement link -->    <referenceBlock name="customer-account-navigation-billing-agreements-link" r...

How to Change Cross-Sell Product Limit in Magento 2?

app/code/Vendor/Extension/etc/frontend/di.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:ObjectManager/etc/config.xsd">     <preference for="Magento\Checkout\Block\Cart\Crosssell" type="Vendor\Extension\Block\Cart\Crosssell" /> </config> Step 2: After that, you must create a Block file in the path below. app/code/Vendor/Extension/Block/Cart/Crosssell.php Now add the following code snippet. <?php   namespace Vendor\Extension\Block\Cart;   use Magento\CatalogInventory\Helper\Stock as StockHelper;   class Crosssell extends \Magento\Checkout\Block\Cart\Crosssell {     public function __construct(         \Magento\Catalog\Block\Product\Context $context,         \Magento\Checkout\Model\Session $checkoutSession,         \Magento\Catalog\Model\Product\...

How to Update Specific Product Quantities using SOAP API?

 <?php use Magento\Framework\App\Bootstrap; try { require './app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $connection = $resource->getConnection(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $request = new SoapClient("https://your_domain/soap/?wsdl&services=integrationAdminTokenServiceV1", array("soap_version" => SOAP_1_2)); // changes your store url. $token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"admin", "password"=>"admin@123")); $request = new SoapClient(     'https://your_domain/soap/default?wsdl&services=catalogInventoryStockRegistryV1',     array( 'soap_version' => SO...

How to Set Product Image using Image URL Link Programmatically in Magento 2?

 <?php use Magento\Framework\AppInterface; try {     require_once __DIR__ . '/app/bootstrap.php'; }  catch (\Exception $e)  {     echo 'Autoload error: ' . $e->getMessage();     exit(1); } try {        $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);        $objectManager = $bootstrap->getObjectManager();        $appState = $objectManager->get('\Magento\Framework\App\State');        $appState->setAreaCode('frontend');        $product_id=1;        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();        $product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);                // Enter Your image URL here        saveimage($product,"https://magecomp.com/medi...

How to Get Active Shipping Methods based on Quote ID in Magento 2?

 <?php namespace  Vendor\Extension\Helper; class Data extends \Magento\Framework\App\Helper\AbstractHelper {     public function __construct(         Context $context,         \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethod)     {         $this->shippingMethod = $shippingMethod;         parent::__construct($context);     }     public function getShippingMethod($quoteId){         $shippinigData = $this->shippingMethod->getList($quoteId);         $shippingMethod = [];         foreach($shippinigData as $shipping)         {             $shippingMethod [] = $shipping-> getMethodTitle();         }         return  $shippingMethod ;     } }

How to Get Cross Sell Products Collection using Root Script in Magento 2

<?php   use Magento\Framework\AppInterface;   try {    require '../app/bootstrap.php'; } catch (\Exception $e) {     echo 'Autoload error: ' . $e->getMessage();     exit(1); } try {  $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);  $objectManager = $bootstrap->getObjectManager();  $appState = $objectManager->get('Magento\Framework\App\State');  $appState->setAreaCode('frontend');         $productId = 3; // Product Id         $crossSellProduct = [];         $objectManager = \Magento\Framework\App\ObjectManager::getInstance();         $product = $objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface')->getById($productId);         $crossSell = $product->getCrossSellProducts();         if (count($crossSell))         {     ...