When try to edit a confugutable i getting VariationMatrix error Magento 2.4.2

I am using Magento 2.4.2 community when I try to edit a configurable product I am getting the below in my store. How to fix it.

Notice: Undefined offset: 0 in
/var/www/html/vendor/magento/module-configurable-product/Model/Product/Type/VariationMatrix.php
on line 47

Exception in
/var/www/html/vendor/magento/framework/App/ErrorHandler.php:61

enter image description here

magento2.3 – Magento 2.4.2: How to change tax label from Tax to Tax(PST/GST/HST)?

We got a custom shipping module created to handle shipping to addresses from within the US and Canada. I would need to change tax label from Tax to Tax(PST/GST/HST) in the payment page only when the destination country is Canada. Below is the whole script handling custom shipping. How can I achieve it?

<?php

namespace PerfectmakeupmirrorsCustomShippingModelCarrier;

use MagentoQuoteModelQuoteAddressRateRequest;
use MagentoShippingModelCarrierAbstractCarrier;
use MagentoShippingModelCarrierCarrierInterface;
use PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier;
use MagentoFrameworkAppResourceConnection;

/**
 * Custom shipping model
 */
class Customshipping extends AbstractCarrier implements CarrierInterface
{
    const FEDEX_METHODS = (
        'EUROPE_FIRST_INTERNATIONAL_PRIORITY' => 'Europe First Priority',
        'FEDEX_1_DAY_FREIGHT' => '1 Day Freight',
        'FEDEX_2_DAY_FREIGHT' => '2 Day Freight',
        'FEDEX_2_DAY' => '2 Day',
        'FEDEX_2_DAY_AM' => '2 Day AM',
        'FEDEX_3_DAY_FREIGHT' => '3 Day Freight',
        'FEDEX_EXPRESS_SAVER' => 'Express Saver',
        'FEDEX_GROUND' => 'Ground',
        'FIRST_OVERNIGHT' => 'First Overnight',
        'GROUND_HOME_DELIVERY' => 'Home Delivery',
        'INTERNATIONAL_ECONOMY' => 'International Economy',
        'INTERNATIONAL_ECONOMY_FREIGHT' => 'Intl Economy Freight',
        'INTERNATIONAL_FIRST' => 'International First',
        'INTERNATIONAL_GROUND' => 'International Ground',
        'INTERNATIONAL_PRIORITY' => 'International Priority',
        'INTERNATIONAL_PRIORITY_FREIGHT' => 'Intl Priority Freight',
        'PRIORITY_OVERNIGHT' => 'Priority Overnight',
        'SMART_POST' => 'Smart Post',
        'STANDARD_OVERNIGHT' => 'Standard Overnight',
        'FEDEX_FREIGHT' => 'Freight',
        'FEDEX_NATIONAL_FREIGHT' => 'National Freight'
    );
    const SHIPPING_STANDARD = 'STD';
    const SHIPPING_2ND_DAY = '2DY';
    const SHIPPING_OVERNIGHT = 'ON';
    protected $_shipping_mode_strings = array(
        self::SHIPPING_STANDARD => 'Standard Ground',
        self::SHIPPING_2ND_DAY => 'Second Day',
        self::SHIPPING_OVERNIGHT => 'Next Day Air',
    );

    /**
     * @var string
     */
    protected $_code = 'customshipping';

    /**
     * @var bool
     */
    protected $_isFixed = true;

    /**
     * @var MagentoShippingModelRateResultFactory
     */
    private $rateResultFactory;

    /**
     * @var MagentoQuoteModelQuoteAddressRateResultMethodFactory
     */
    private $rateMethodFactory;

    /**
     * @var PerfectmakeupmirrorsCustomShippingHelperData
     */
    private $helper;

    /**
     * @var PsrLogLoggerInterface
     */
    protected $_logger;

    /**
     * @var PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier;
     */
    private $carrierFedex;

    /**
     * @var MagentoFrameworkAppResourceConnection;
     */
    protected $resource;

    /**
     * @var MagentoFrameworkAppResourceConnection;
     */
    protected $scopeConfig;

    /**
     * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
     * @param MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory
     * @param PsrLogLoggerInterface $logger
     * @param MagentoShippingModelRateResultFactory $rateResultFactory
     * @param MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory
     * @param MagentoFrameworkAppResourceConnection $resource
     * @param array $data
     */
    public function __construct(
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory,
        PsrLogLoggerInterface $logger,
        MagentoShippingModelRateResultFactory $rateResultFactory,
        MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory,
        PerfectmakeupmirrorsCustomShippingHelperData $helper,
        PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier $carrierFedex,
        MagentoFrameworkAppResourceConnection $resource,
        array $data = ()
    ) {
        parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);

        $this->rateResultFactory = $rateResultFactory;
        $this->rateMethodFactory = $rateMethodFactory;
        $this->carrierFedex = $carrierFedex;
        $this->_logger = $logger;
        $this->helper = $helper;
        $this->resource = $resource;
        $this->scopeConfig = $scopeConfig;
    }

    /**
     * Custom Shipping Rates Collector
     *
     * @param RateRequest $request
     * @return MagentoShippingModelRateResult|bool
     */
    public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }
        
        if ($request->getDestCountryId() == "CA") {
            // Shipping to Canada.
            // 1. Get the array of method objects from $fedex_results object
            // 2. Loop through the array of method objects to set carrier.
            // 3. Set carrier to custom shipping.
            // 4. Add brokerage to the shipping cost based on the table canada_brokerage_fees.
            $fedex_results = $this->carrierFedex->collectRates($request);

            // MagentoQuoteModelQuoteAddressRateResultMethod $methods
            $methods = $fedex_results->getAllRates();
            foreach ($methods as $method) {
                // 3. Set carrier to custom shipping.
                $method->setCarrier($this->_code);
                $method->setMethodTitle("(including brokerage and duty)");
                $method->setCarrierTitle("");

                // Get subtotal from the $request object.
                // The request object is not giving the subtotal directly.
                // Using Quote object.
                // Refer https://magento.stackexchange.com/questions/341393/magento-2-4-2-how-to-get-order-sub-total-in-my-custom-module/341410#341410
                $quote = null;
                $items = $request->getAllItems();
                foreach($items as $item) {
                    /** @var Quote $quote */
                    $quote = $item->getQuote();
                    break;
                }
                if (!$quote) {
                    return false;
                }
                $subtotal = $quote->getSubtotal();                

                // Convert subtotal from USD to CAD
                // Get current CAD rate.
                $current_usd_to_cad_rate = $this->get_magento_system_info("pmm/currency_conversion/usd_to_cad_conversion");
                $subtotal_cad = $subtotal * floatval($current_usd_to_cad_rate);

                // Use table canada_brokerage_fee in Magento DB
                // Create DB connection
                // http://blog.chapagain.com.np/magento-2-run-custom-sql-query/
                $connection = $this->resource->getConnection();
                $tableName = $this->resource->getTableName('canada_brokerage_fees');

                // Compute brokerage.
                // Fetch relevant fee from the table canada_brokerage_fees 
                // based on the merchandise total.
                $sql = $connection->select()->from($tableName)->where('max_merchandise_cost <= ?', $subtotal_cad)
                ->order('brokerage_cost_cad DESC')->limit(1);
                $result = $connection->fetchAll($sql);                
                $brokerage_cost_cad = $result(0)('brokerage_cost_cad') ?? 0;

                // TODO
                // Compute duty and add it to brokerage_cost_cad.
                // All mirror and skin care products are duty free.

                // Set new price with brokerage added to the shipping cost.
                $method->setPrice($method->getPrice() + $brokerage_cost_cad);
            }
            return $fedex_results;
        } elseif (($request->getDestRegionCode() == "AK") || ($request->getDestRegionCode() == "HI") || ($request->getDestCountryId() == "PR")) {
            // For Alaska, Hawaii, and Puerto Rico
            // We want to get the shipping computation using Fedex

            $fedex_results = $this->carrierFedex->collectRates($request);
            // 1. Get the array of method objects from $fedex_results object
            // 2. Loop through the array of method objects to set carrier.
            // 3. Set carrier to custom shipping. 

            // MagentoQuoteModelQuoteAddressRateResultMethod $methods
            $methods = $fedex_results->getAllRates();
            foreach ($methods as $method) {
                $method->setCarrier($this->_code);
                $method->setMethodTitle("(including brokerage and duty)");
                $method->setCarrierTitle("");
            }
            return $fedex_results;
        }

        // Below Processing is for Mainland USA.
        // Custom Shipping needs to be computed.
        /** @var MagentoShippingModelRateResult $result */
        $result = $this->rateResultFactory->create();

        /** @var MagentoQuoteModelQuoteAddressRateResultMethod $method */
        $method = $this->rateMethodFactory->create();

        $method->setCarrier($this->_code);
        $method->setCarrierTitle($this->getConfigData('title'));

        $method->setMethod($this->_code);
        $method->setMethodTitle($this->getConfigData('name'));

        $this->_logger->info(__FILE__ . ': At Start');

        // Get all the items.
        // NOTE: This getAllItems here is related to Quote and not the order.
        if ((!($items = $request->getAllItems())) or (count($items) == 0)) {
            return FALSE;
        }

        //Standard code commented. Custom code added.
        //$shippingCost = (float)$this->getConfigData('shipping_cost');
        $shippingCost = (float)$this->helper->compute_standard_shipping_cost($items);

        $method->setPrice($shippingCost);
        $method->setCost($shippingCost);

        $result->append($method);

        return $result;
    }

    /**
     * Get all the allowed methods for Custom Shipping. This sends the CustomShipping
     * method as well as all the allowed methods of Fedex. This is required to ensure
     * the Fedex shipping methods to be considered as valid methods.
     * 
     * @return array
     */
    public function getAllowedMethods()
    {
        $custom_shipping_methods = ($this->_code => $this->getConfigData('name'));
        $allowed_methods = array_merge($custom_shipping_methods, $this->FEDEX_METHODS);
        return $allowed_methods;
    }

    /**
     * get_magento_system_info - receives the path as parameter.
     * This parameter holds the path to the field.
     * This function returns a value in Magento core_config_data table.
     * 
     * @param string $path
     * @return string $config_data
     */
    private function get_magento_system_info($path)
    {
        // Refer https://store.magenest.com/blog/get-set-config-data-programmatically-magento-2/
        // Refer https://firebearstudio.com/blog/how-to-write-and-get-config-values-by-scope-in-magento-2.html

        // Call functions to get config data with default (global) scope
        return $this->scopeConfig->getValue($path);
    }
}

magento2.4.2 – Error during compilation after upgrade from 2.4.1 to 2.4.2

I have below error while running
php bin/magento setup:di:compile
Compilation was started.
Repositories code generation… 1/9 [==>—————-] 11% < 1 sec 105.0 MiB

Interception cache generation… 6/9 [=========>—-] 66% 37 secs 454.0 MiBErrors during compilation:
MagentoFrameworkSetupOptionAbstractConfigOption
Incompatible argument type: Required type: int. Actual type: string; File:
/home/public_html/vendor/magento/framework/Setup/Option/AbstractConfigOption.php

Total Errors Count: 1

In Log.php line 92:

Error during compilation

setup:di:compile

checkout – Magento 2.4.2: How to get order sub total in my custom module?

With the code below, I am trying to get the order sub total. Please note I am querying the table that I created in the Magento Database. $subtotal = $request->getOrderSubtotal(); doesn’t get the subtotal.

<?php

namespace PerfectmakeupmirrorsCustomShippingModelCarrier;

use MagentoQuoteModelQuoteAddressRateRequest;
use MagentoShippingModelCarrierAbstractCarrier;
use MagentoShippingModelCarrierCarrierInterface;
use PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier;
use MagentoFrameworkAppResourceConnection;

/**
 * Custom shipping model
 */
class Customshipping extends AbstractCarrier implements CarrierInterface
{
    const CAD_RATE = 1.26;
    const FEDEX_METHODS = (
        'EUROPE_FIRST_INTERNATIONAL_PRIORITY' => 'Europe First Priority',
        'FEDEX_1_DAY_FREIGHT' => '1 Day Freight',
        'FEDEX_2_DAY_FREIGHT' => '2 Day Freight',
        'FEDEX_2_DAY' => '2 Day',
        'FEDEX_2_DAY_AM' => '2 Day AM',
        'FEDEX_3_DAY_FREIGHT' => '3 Day Freight',
        'FEDEX_EXPRESS_SAVER' => 'Express Saver',
        'FEDEX_GROUND' => 'Ground',
        'FIRST_OVERNIGHT' => 'First Overnight',
        'GROUND_HOME_DELIVERY' => 'Home Delivery',
        'INTERNATIONAL_ECONOMY' => 'International Economy',
        'INTERNATIONAL_ECONOMY_FREIGHT' => 'Intl Economy Freight',
        'INTERNATIONAL_FIRST' => 'International First',
        'INTERNATIONAL_GROUND' => 'International Ground',
        'INTERNATIONAL_PRIORITY' => 'International Priority',
        'INTERNATIONAL_PRIORITY_FREIGHT' => 'Intl Priority Freight',
        'PRIORITY_OVERNIGHT' => 'Priority Overnight',
        'SMART_POST' => 'Smart Post',
        'STANDARD_OVERNIGHT' => 'Standard Overnight',
        'FEDEX_FREIGHT' => 'Freight',
        'FEDEX_NATIONAL_FREIGHT' => 'National Freight'
    );
    const SHIPPING_STANDARD = 'STD';
    const SHIPPING_2ND_DAY = '2DY';
    const SHIPPING_OVERNIGHT = 'ON';
    protected $_shipping_mode_strings = array(
        self::SHIPPING_STANDARD => 'Standard Ground',
        self::SHIPPING_2ND_DAY => 'Second Day',
        self::SHIPPING_OVERNIGHT => 'Next Day Air',
    );

    /**
     * @var string
     */
    protected $_code = 'customshipping';

    /**
     * @var bool
     */
    protected $_isFixed = true;

    /**
     * @var MagentoShippingModelRateResultFactory
     */
    private $rateResultFactory;

    /**
     * @var MagentoQuoteModelQuoteAddressRateResultMethodFactory
     */
    private $rateMethodFactory;

    /**
     * @var PerfectmakeupmirrorsCustomShippingHelperData
     */
    private $helper;

    /**
     * @var PsrLogLoggerInterface
     */
    protected $_logger;

    private $carrierFedex;

    protected $resource;

    /**
     * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
     * @param MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory
     * @param PsrLogLoggerInterface $logger
     * @param MagentoShippingModelRateResultFactory $rateResultFactory
     * @param MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory
     * @param MagentoFrameworkAppResourceConnection $resource
     * @param array $data
     */
    public function __construct(
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory,
        PsrLogLoggerInterface $logger,
        MagentoShippingModelRateResultFactory $rateResultFactory,
        MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory,
        PerfectmakeupmirrorsCustomShippingHelperData $helper,
        PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier $carrierFedex,
        MagentoFrameworkAppResourceConnection $resource,
        array $data = ()
    ) {
        parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data, $resource);

        $this->rateResultFactory = $rateResultFactory;
        $this->rateMethodFactory = $rateMethodFactory;
        $this->carrierFedex = $carrierFedex;
        $this->_logger = $logger;
        $this->helper = $helper;
        $this->resource = $resource;
    }

    /**
     * Custom Shipping Rates Collector
     *
     * @param RateRequest $request
     * @return MagentoShippingModelRateResult|bool
     */
    public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }
        
        $this->_logger->info("Start of Custom Shipping collectRates");
        if ($request->getDestCountryId() == "CA") {
            $this->_logger->info("Country ID: " . $request->getDestCountryId());
            $fedex_results = $this->carrierFedex->collectRates($request);
            // 1. Get the array of method objects from $fedex_results object
            // 2. Loop through the array of method objects to set carrier.
            // 3. Set carrier to custom shipping. 
            // 4. Add brokerage to the shipping cost based on the table canada_brokerage_fees.

            // MagentoQuoteModelQuoteAddressRateResultMethod $methods
            $methods = $fedex_results->getAllRates();
            $this->_logger->info("At line 136");
            foreach ($methods as $method) {
                $this->_logger->info("At line 138");
                $method->setCarrier($this->_code);
                // Set new price with brokerage added to the shipping cost.
                // Get subtotal from the $request object.
                // Recalculate subtotal in CAD
                // Create table canada_brokerage_fee in Magento DB
                // Compute brokerage.
                $subtotal = $request->getOrderSubtotal();
                $this->_logger->info("Sub total in USD: " . $subtotal);

                // Convert $subtotal from USD to CAD
                // 1 USD = 1.26 CAD
                $subtotal_cad = ($subtotal * 1.26);
                $this->_logger->info("Sub total in CAD: " . $subtotal_cad);

                // Create DB connection
                // http://blog.chapagain.com.np/magento-2-run-custom-sql-query/
                $connection    = $this->resource->getConnection();
                $tableName     = $this->resource->getTableName('canada_brokerage_fees');
                $this->_logger->info("At line 157");

                // Fetch relevant fee from the table canada_brokerage_fees 
                // based on the merchandise total.
                $sql = "SELECT brokerage_cost_cad FROM " . $tableName .  
                       " WHERE max_merchandise_cost <=" . $subtotal_cad . " ORDER BY brokerage_cost_cad DESC LIMIT 1";
                $result = $connection->query($sql);   
                $brokerage_cost_cad = $result('brokerage_cost_cad');
                $this->_logger->info("At line 165");
                
                $this->_logger->info("brokerage in CAD: " . $brokerage_cost_cad);
                $method->setPrice($method->getPrice + $brokerage_cost_cad);
                $this->_logger->info("At line 169");
            }

            return $fedex_results;
        }

        /** @var MagentoShippingModelRateResult $result */
        $result = $this->rateResultFactory->create();

        /** @var MagentoQuoteModelQuoteAddressRateResultMethod $method */
        $method = $this->rateMethodFactory->create();

        $method->setCarrier($this->_code);
        $method->setCarrierTitle($this->getConfigData('title'));

        $method->setMethod($this->_code);
        $method->setMethodTitle($this->getConfigData('name'));

        $this->_logger->info(__FILE__ . ': At Start');

        // Get all the items.
        // NOTE: This getAllItems here is related to Quote and not the order.
        if ((!($items = $request->getAllItems())) or (count($items) == 0)) {
            return FALSE;
        }

        // $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        // $attributeSet = $objectManager->create('MagentoEavApiAttributeSetRepositoryInterface');
        // $attributeSetRepository = $attributeSet->get(9);
        // $attribute_set_name = $attributeSetRepository->getAttributeSetName();
        // $this->_logger->info(__FILE__ . ": Attribute Set Name = $attribute_set_name");

        //Standard code commented. Custom code added.
        //$shippingCost = (float)$this->getConfigData('shipping_cost');
        $shippingCost = (float)$this->helper->compute_standard_shipping_cost($items);

        $method->setPrice($shippingCost);
        $method->setCost($shippingCost);

        $result->append($method);

        return $result;
    }

    /**
     * @return array
     */
    public function getAllowedMethods()
    {
        $custom_shipping_methods = ($this->_code => $this->getConfigData('name'));
        $allowed_methods = array_merge($custom_shipping_methods, $this->FEDEX_METHODS);
        return $allowed_methods;
    }
}

collection – Custom Sorting on category page not working in Magento 2.4.2

I have Magento 2.4.2.

I have written a custom code to add A-Z & Z-A filters on category page.

I have added dependency injection using below code

<preference for="MagentoCatalogBlockProductProductListToolbar" type="VendorModuleNamePluginProductProductListToolbar" />

In below file, I have overridden setCollection function

VendorModuleNamePluginProductProductListToolbar

public function setCollection($collection)
    {
        $this->_collection = $collection;
        $this->_collection->setCurPage($this->getCurrentPage());

        $limit = (int)$this->getLimit();
        if ($limit) {
            $this->_collection->setPageSize($limit);
        }

        if ($this->getCurrentOrder()) {
            switch ($this->getCurrentOrder()) {
            case 'az':
                    $this->_collection->setOrder('name', 'asc');
                    break;
                case 'za':
                    $this->_collection->setOrder('name', 'desc');
                    break;


                    ......

The issue is that this function is called twice, the first time it returns proper result (used X-debug to debug query of collection).
And the second time it is called, it messes up the query of the collection by adding some entity_id filter and sorters.

Due to which the collection expected isn’t coming.

What could be the reason of above function getting called twice.

magento2 – How to add CSS that works only in Checkout page Mangento 2.4.2

If CSS is merged then, that merged css will call in all page. Otherwise, you can add css in checkout_index_index.xml file :

<head>
        <css src="https://magento.stackexchange.com/Magento_Checkout::css/customcheckout.css"/>
</head>

File should be available on

app/design/frontend/VendorName/ThemeName/Magento_Checkout/web/css/customcheckout.css

And in css file add .checkout-index-index class before all css’s class name. So, that css only apply on checkout page.

Suggestion : Instead of create css file. Add css in less file.

How to design a mobile responsive design using Page builder Magento 2.4.2

Good Morning
We are trying to design my home page fully using page builder, but the page builder is not working in responsive we had tried the page builder options to adopt in responsive but we can achieve what we need.

  1. First the slider the slider is showing better in desktop when we go to responsive the slider and image is not getting small it shows very big only.
  2. I need to show the 8 icons in one row at desktop version but when it comes to mobile need to show the 8 icons in two row set of 4 but when it comes to mobile version it show one buy one.

magento2.4.2 – Error while setup Magento 2.4.2

I am trying to install Magento 2.4.2 , and I am getting this error

PHP Warning:  require(C:xampp-cleanhtdocsmagento242vendorcomposer/../phpsta
n/phpstan/bootstrap.php): failed to open stream: No such file or directory in C:
xampp-cleanhtdocsmagento242vendorcomposerautoload_real.php on line 73

The command that I am used that is causing this error is :

php bin/magento setup:install --base-url="http://ahmed.magento/" --db-host="localhost" --db-name="magento242" --db-user="root" --db-password="" --admin-firstname="admin" --admin-lastname="admin" --admin-email="contact@code.tn" --admin-user="admin" --admin-password="azerty123" --language="en_US" --currency="USD" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin" --search-engine=elasticsearch7 --elasticsearch-host="localhost" --elasticsearch-port=9200

I am using as system :
Windows 10

with xampp software ,
Elasticsearch is running and working.
Do anyone has any idea about this problem?
Thanks in advance