Author: ptgwpadmin

  • Warning: Trying to access array offset on null in vendor/magento/framework/Mview/View/Subscription.php on line 357

    Warning: Trying to access array offset on null in vendor/magento/framework/Mview/View/Subscription.php on line 357

    On the Magento 2.4.8
    Open file: vendor/magento/framework/Mview/TriggerCleaner.php

    public function removeTriggers(): bool
    {
    $this->getDbTriggers();

        // Get list of views that are enabled
        $viewCollection = $this->viewCollectionFactory->create();
        $viewList = $viewCollection->getViewsByStateMode(StateInterface::MODE_ENABLED);
    
        // Check triggers declaration for the enabled views and update them if any changes
        foreach ($viewList as $view) {
            $subscriptions = $view->getSubscriptions();
            foreach ($subscriptions as $subscriptionConfig) {
                /* @var $subscription Subscription */
                $subscription = $view->initSubscriptionInstance($subscriptionConfig);
                $viewTriggers = $subscription->create(false)->getTriggers();
                $this->processViewTriggers($viewTriggers, $subscription);
            }
        }
    
        // Remove any remaining triggers from db that are not linked to a view
        $remainingTriggers = array_diff_key($this->DbTriggers, $this->processedTriggers);
        foreach ($remainingTriggers as $trigger) {
            $view = $this->createViewByTableName($trigger['EVENT_OBJECT_TABLE']);
            // $view->unsubscribe();
            // $view->getState()->delete();
    // Add this code:
            if ($view->getActionClass()) {
                $view->unsubscribe();
                $view->getState()->delete();
            }
        }
    
        return true;
    }
  • How to Fix “Invalid address id” Error When Adding Products to Cart in Magento 2

    One of the common issues Magento 2 developers and store owners may face is the
    “Invalid address id” error when a logged-in customer tries to add
    products to the shopping cart.
    This problem usually occurs when the system gets confused due to multiple active
    quotes being assigned to the same customer.

    Why does this happen?

    In Magento 2, each logged-in customer has an active quote
    (shopping cart record) in the database.
    However, in certain scenarios, the customer may end up with
    more than one active quote, which leads to conflicts.

    Common reasons include:

    • Multiple devices or sessions creating new quotes simultaneously.
    • Custom modules or third-party extensions that override quote creation logic.
    • Incomplete checkout sessions leaving behind active quotes that were never closed.

    Step-by-Step Solution

    To resolve the issue, you need to inspect the quote table in your
    Magento 2 database and clean up duplicate active quotes for the affected customer.

    1. Check all active quotes for the customer

    
    SELECT entity_id, is_active
    FROM quote
    WHERE customer_id = <customer_id>;
      

    Replace <customer_id> with the actual customer ID.
    You can find this ID from your Magento Admin panel under:
    Customers → All Customers.

    2. Deactivate duplicate quotes

    If you see more than one record where is_active = 1,
    it means the customer has multiple active carts.
    To deactivate them, run the following query:

    
    DELETE FROM quote
    WHERE customer_id = <customer_id> 
      AND is_active = 1;
      

    ⚠️ Important: This will delete all active quotes for the customer.
    Make sure to confirm with the customer before proceeding,
    as it will clear their shopping cart.

    Best Practices

    • Check custom extensions that might be creating extra quotes.
    • Ensure your checkout flow is properly closing inactive quotes.
    • Always test in a staging environment before applying queries to production.
    • Take a database backup before making direct changes.

    Conclusion

    The “Invalid address id” error in Magento 2 is usually caused by
    duplicate active quotes for a customer.
    By cleaning up the quote table and ensuring that only one active
    quote exists per customer, you can quickly resolve this issue.
    Long-term, review any customizations or extensions that interfere with cart creation
    to prevent the problem from recurring.