magento2.3 – PHP Fatal error: Uncaught Error: Cannot instantiate interface Magento 2.3

When running php bin/magento setup:upgrade i see this error.

{"messages":{"error":({"code":500,"message":"Server internal error. See details in report api/499296787794"})}}

Searching on my error_log_php i see this

    PHP Fatal error:  Uncaught Error: Cannot instantiate interface MagentoDownloadableApiDomainManagerInterface in /home/user/MySite/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50
Stack trace:
#0 /home/user/MySite/vendor/magento/framework/ObjectManager/ObjectManager.php(70): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->create('Magento\Downloa...')
#1 /home/user/MySite/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(160): MagentoFrameworkObjectManagerObjectManager->get('Magento\Downloa...')
#2 /home/user/MySite/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgument(Array, 'Magento\Downloa...', NULL, 'domainManager', 'Magento\Downloa...')
#3 /home/user/MySite/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): MagentoFrameworkObje in /home/user/MySite/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php on line 50

I’ve seen suggestions for deleting var and generated folder, but it didn’t work.
I’m interested in solving this since I need to install a new module.

What could be the issue, and I could solve this?


EDIT

I’ve also found that it could be a problem related to the leftovers of a badly removed module. If that is the case, how could I check for it? I haven’t installed anything recently, so any issue related to this would be hard to track only with memory.

magento2.3 – Shipping cost calculated on subtotal Magento 2.3

I need to set my shipping amount to be a percentage of the subtotal

My requirement would be: minimum of 7€ and 7% of the subtotal if more.

I can see that in flat rate you can set a fee with a percentage, but it’s calculated o the shipping cost, and not from the order itself.
(ex. it’s giving me 7,49€ with a shipping price of 7€ and a fee of 7%, while the subtotal is 10€)

Can I get the wonted requirement with default settings? If not, which extension should I use?

magento2.3 – How to add firebase cdn’s in magento2?

I am trying to add add web push notification using firebase in my magento2 app. I tested it on a simple web application using following code.

<html>
<title>Firebase Messaging Demo</title>
<style>
    div {
        margin-bottom: 15px;
    }
</style>
<body>
<!--     <form method="post" action="send.php">
    
    <input type="submit" name="submit">
</form> -->
    <div id="msg"></div>
    <div id="token" ></div>
    <div id="notis"></div>
    <div id="err"></div>
    <script src="https://www.gstatic.com/firebasejs/7.16.1/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.16.1/firebase-messaging.js"></script>
    <script>
        MsgElem = document.getElementById("msg");
        TokenElem = document.getElementById("token");
        NotisElem = document.getElementById("notis");
        ErrElem = document.getElementById("err");
        // Initialize Firebase
        // TODO: Replace with your project's customized code snippet
        var config = {
    "apiKey": "xyz",
    "authDomain": "xyz",
    "projectId": "xyz",
    "storageBucket": "xyz",
    "messagingSenderId": "xyz",
    "appId": "xyz",
    "measurementId": "xyz"

           
        };
        firebase.initializeApp(config);

        const messaging = firebase.messaging();
        messaging
            .requestPermission()
            .then(function () {
                MsgElem.innerHTML = "Notification permission granted." 
                console.log("Notification permission granted.");
                
                // get the token in the form of promise

                return messaging.getToken()
            })
            .then(function(token) {
                TokenElem.innerHTML =token
                
            })
            .catch(function (err) {
                ErrElem.innerHTML =  ErrElem.innerHTML + "; " + err
                console.log("Unable to get permission to notify.", err);
            });

        let enableForegroundNotification = true;
        messaging.onMessage(function(payload) {
            console.log("Message received. ", payload);
            NotisElem.innerHTML = NotisElem.innerHTML + JSON.stringify(payload);

            if(enableForegroundNotification) {
                const {title, ...options} = JSON.parse(payload.data.notification);
                navigator.serviceWorker.getRegistrations().then(registration => {
                    registration(0).showNotification(title, options);
                });
            }
        });
    </script>

    </body>
   


</html>

Then I am able to send web push notification using curl command.But when I try to to do the same in magento2 it gives errors and does not let JS cdn’s to be added in my module.I am doing this using require-js.My requirejs-config.js file looks like this.

var config = {
    paths: {
        "*": {
            "firebaseapp": "https://www.gstatic.com/firebasejs/7.16.1/firebase-app.js",
            "firebasemessaging": "https://www.gstatic.com/firebasejs/7.16.1/firebase-messaging.js"
 
        }
    },
    shim: {
        'firebaseapp': {
            deps: ('jquery')
        },
        'firebasemessaging': {
            deps: ('jquery')
        }
    }
};

And .phtml file looks like this.

<?php

?>
<label><?= __("Data  from Block is ") ?></label>
<h1><?= $block->getText() ?></h1>
<div id="test"></div>

<script>
require((
    'jquery',
    'firebaseapp',
    'firebasemessaging' 
), function ($,firebaseapp,firebasemessaging) {

    console.log("working");

});
</script>

But it gives following error.
The resource from “http://localhost/magento235/pub/static/version1610370022/frontend/Vendor1/Customtheme/en_US/firebasemessaging.js” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff).

magento2.3 – How to enable ajax for adding to cart up-sell, cross-sell and related products in Magento 2.3.6?

Replace the below code in items.phtml,

path : app/design/frontend/(your_theme)/Magento_catalog/templates/product/list

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
// phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect

/* @var $block MagentoCatalogBlockProductAbstractProduct */
use MagentoFrameworkAppActionAction;
?>

<?php
switch ($type = $block->getType()) {

    case 'related-rule':
        if ($exist = $block->hasItems()) {
            $type = 'related';
            $class = $type;

            $image = 'related_products_list';
            $title = __('Related Products');
            $items = $block->getAllItems();
            $limit = $block->getPositionLimit();
            $shuffle = (int) $block->isShuffled();
            $canItemsAddToCart = $block->canItemsAddToCart();

            $showAddTo = true;
            $showCart = false;
            $templateType = null;
            $description = false;
        }
        break;

    case 'related':
        /** @var MagentoCatalogBlockProductProductListRelated $block */
        if ($exist = $block->getItems()->getSize()) {
            $type = 'related';
            $class = $type;

            $image = 'related_products_list';
            $title = __('Related Products');
            $items = $block->getItems();
            $limit = 0;
            $shuffle = 0;
            $canItemsAddToCart = $block->canItemsAddToCart();

            $showAddTo = true;
            $showCart = false;
            $templateType = null;
            $description = false;
        }
        break;

    case 'upsell-rule':
        if ($exist = $block->hasItems()) {
            $type = 'upsell';
            $class = $type;

            $image = 'upsell_products_list';
            $title = __('We found other products you might like!');
            $items = $block->getAllItems();
            $limit = $block->getPositionLimit();
            $shuffle = (int) $block->isShuffled();

            $showAddTo = false;
            $showCart = false;
            $templateType = null;
            $description = false;
            $canItemsAddToCart = false;
        }
        break;

    case 'upsell':
        /** @var MagentoCatalogBlockProductProductListUpsell $block */
        if ($exist = count($block->getItemCollection()->getItems())) {
            $type = 'upsell';
            $class = $type;

            $image = 'upsell_products_list';
            $title = __('We found other products you might like!');
            $items = $block->getItemCollection()->getItems();
            $limit = $block->getItemLimit('upsell');
            $shuffle = 0;

            $showAddTo = false;
            $showCart = false;
            $templateType = null;
            $description = false;
            $canItemsAddToCart = false;
        }
        break;

    case 'crosssell-rule':
        /** @var MagentoCatalogBlockProductProductListCrosssell $block */
        if ($exist = $block->hasItems()) {
            $type = 'crosssell';
            $class = $type;

            $image = 'cart_cross_sell_products';
            $title = __('More Choices:');
            $items = $block->getItemCollection();

            $showAddTo = true;
            $showCart = true;
            $templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
            $description = false;
            $canItemsAddToCart = false;
        }
        break;

    case 'crosssell':
        /** @var MagentoCatalogBlockProductProductListCrosssell $block */
        if ($exist = count($block->getItems())) {
            $type = 'crosssell';
            $class = $type;

            $image = 'cart_cross_sell_products';
            $title = __('More Choices:');
            $items = $block->getItems();

            $showAddTo = true;
            $showCart = true;
            $templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
            $description = false;
            $canItemsAddToCart = false;
        }
        break;

    case 'new':
        if ($exist = $block->getProductCollection()) {
            $type = 'new';
            $mode = 'grid';
            $type = $type . ' ' . $mode;

            $class = 'widget' . ' ' . $type;

            $image = 'new_products_content_widget_grid';
            $title = __('New Products');
            $items = $exist;

            $showAddTo = true;
            $showCart = true;
            $templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
            $description = ($mode == 'list') ? true : false;
            $canItemsAddToCart = false;
        }
        break;

    default:
        $exist = null;
}
?>

<?php if ($exist) :?>

<?php if ($type == 'related' || $type == 'upsell') :?>
<?php if ($type == 'related') :?>
<div class="block <?= $block->escapeHtmlAttr($class) ?>" data-mage-init='{"relatedProducts":{"relatedCheckbox":".related.checkbox"}}' data-limit="<?= $block->escapeHtmlAttr($limit) ?>" data-shuffle="<?= /* @noEscape */ $shuffle ?>">
    <?php else :?>
    <div class="block <?= $block->escapeHtmlAttr($class) ?>" data-mage-init='{"upsellProducts":{}}' data-limit="<?= $block->escapeHtmlAttr($limit) ?>" data-shuffle="<?= /* @noEscape */ $shuffle ?>">
        <?php endif; ?>
        <?php else :?>
        <div class="block <?= $block->escapeHtmlAttr($class) ?>">
            <?php endif; ?>
            <div class="block-title title">
                <strong id="block-<?= $block->escapeHtmlAttr($class) ?>-heading" role="heading" aria-level="2"><?= $block->escapeHtml($title) ?></strong>
            </div>
            <div class="block-content content" aria-labelledby="block-<?= $block->escapeHtmlAttr($class) ?>-heading">
                <?php if ($type == 'related' && $canItemsAddToCart) :?>
                    <div class="block-actions">
                        <?= $block->escapeHtml(__('Check items to add to the cart or')) ?>
                        <button type="button" class="action select" data-role="select-all"><span><?= $block->escapeHtml(__('select all')) ?></span></button>
                    </div>
                <?php endif; ?>
                <div class="products wrapper grid products-grid products-<?= $block->escapeHtmlAttr($type) ?>">
                    <ol class="products list items product-items">
                        <?php foreach ($items as $_item) :?>
                            <?php $available = ''; ?>
                            <?php if (!$_item->isComposite() && $_item->isSaleable() && $type == 'related') :?>
                                <?php if (!$_item->getRequiredOptions()) :?>
                                    <?php $available = 'related-available'; ?>
                                <?php endif; ?>
                            <?php endif; ?>
                            <?php if ($type == 'related' || $type == 'upsell') :?>
                                <li class="item product product-item" style="display: none;">
                            <?php else :?>
                                <li class="item product product-item">
                            <?php endif; ?>
                            <div class="product-item-info <?= /* @noEscape */ $available ?>">
                                <?= /* @noEscape */ '<!-- ' . $image . '-->' ?>
                                <a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>" class="product photo product-item-photo">
                                    <?= $block->getImage($_item, $image)->toHtml() ?>
                                </a>
                                <div class="product details product-item-details">
                                    <strong class="product name product-item-name"><a class="product-item-link" title="<?= $block->escapeHtmlAttr($_item->getName()) ?>" href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>">
                                            <?= $block->escapeHtml($_item->getName()) ?></a>
                                    </strong>

                                    <?= /* @noEscape */ $block->getProductPrice($_item) ?>

                                    <?php if ($templateType) :?>
                                        <?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
                                    <?php endif; ?>

                                    <?php if ($canItemsAddToCart && !$_item->isComposite() && $_item->isSaleable() && $type == 'related') :?>
                                        <?php if (!$_item->getRequiredOptions()) :?>
                                            <div class="field choice related">
                                                <input type="checkbox" class="checkbox related" id="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>" name="related_products()" value="<?= $block->escapeHtmlAttr($_item->getId()) ?>" />
                                                <label class="label" for="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>"><span><?= $block->escapeHtml(__('Add to Cart')) ?></span></label>
                                            </div>
                                        <?php endif; ?>
                                    <?php endif; ?>

                                    <?php if ($showAddTo || $showCart) :?>
                                        <div class="product actions product-item-actions">
                                            <?php if ($showCart) :?>
                                                <div class="actions-primary">
                                                    <?php if ($_item->isSaleable()) :?>
                                                        <?php if ($_item->getTypeInstance()->hasRequiredOptions($_item)) :?>
                                                            <button class="action tocart primary" data-mage-init='{"redirectUrl": {"url": "<?= $block->escapeUrl($block->getAddToCartUrl($_item)) ?>"}}' type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
                                                                <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
                                                            </button>
                                                        <?php else :?>
                                                            <?php $postDataHelper = $this->helper(MagentoFrameworkDataHelperPostHelper::class);
                                                            $postData = $postDataHelper->getPostData($block->escapeUrl($block->getAddToCartUrl($_item)), ('product' => $_item->getEntityId()))
                                                            ?>
                                                    <form data-role="tocart-form" data-product-id="<?= $block->escapeHtml($_item->getId()) ?>" action="<?php /* @escapeNotVerified */ echo $postParams; ?>" method="post">
                                                        <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams; ?>">
                                                        <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams; ?>">
                                                        <?php echo $block->getBlockHtml('formkey')?>

                                                        <button class="action tocart primary"
                                                                    data-post='<?= /* @noEscape */ $postData ?>'
                                                                    type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
                                                                <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
                                                            </button>
                                                    </form>
                                                        <?php endif; ?>
                                                    <?php else :?>
                                                        <?php if ($_item->getIsSalable()) :?>
                                                            <div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
                                                        <?php else :?>
                                                            <div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                </div>
                                            <?php endif; ?>

                                            <?php if ($showAddTo) :?>
                                                <div class="secondary-addto-links actions-secondary" data-role="add-to-links">
                                                    <?php if ($addToBlock = $block->getChildBlock('addto')) :?>
                                                        <?= $addToBlock->setProduct($_item)->getChildHtml() ?>
                                                    <?php endif; ?>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                            </li>
                        <?php endforeach ?>
                    </ol>
                </div>
            </div>
        </div>
  <script type="text/x-magento-init">
    {
        "(data-role=tocart-form), .form.map.checkout": {
            "catalogAddToCart": {
                "product_sku": "<?= /* @NoEscape */ $_item->getSku() ?>"
            }
        }
    }
  </script>
        <?php endif;?>

magento2.3 – PHP: How to move an array element with an unknown key to end?

<?php $array = array(array
    (
        "value" => 4,
        "label" => "red",
    ),
    array
    (
        "value" => 5,
        "label" => "pink",
    ),
    array
    (
        "value" => 6,
        "label" => "blue",
    ),
    array
    (
        "value" => 7,
        "label" => "yellow",
    ),
    array
    (
        "value" => 8,
        "label" => "white",
    ),
    array
    (
        "value" => 9,
        "label" => "black",
    ),
);

foreach ($array as $key => $val) {
    if ($val("label") == 'blue') {
        $item = $array($key);
        unset($array($key));
        array_push($array, $item);
        break;
    }
}

print_r($array);

$val(“label”) change it on your need

Thanks

magento2.3 – Category Side Filter not showing on up on Left just for one Category?

I recently restructured my categories. I noticed however, that one category which is set to is Anchored ‘YES’. However, it is not showing left sidbar category filters for my sub categories. Images below.

What is should be

enter image description here

What it is showing for e-liquids, Anchor is set to ‘YES’. However No Category left side bar? Only not showing for this category. All other categories work.

enter image description here

Showing backend. I created the E-Liquds sub folder and moved A-Z sub folders inside and set ancher to YES but this category is not working.

enter image description here

Any Help would be much appriciated.

magento2.3 – Magento 2: How to upload multiple images to Customer from Admin

Wanting to upload multiple images to a customer account via the admin. Below I’ve created a custom customer attribute that allows a single image / file upload, but how can I make this a multiple file upload?

InstallData.php

<?php

namespace MyCompanyMyModuleSetup;

use MagentoEavSetupEavSetupFactory;
use MagentoCustomerSetupCustomerSetupFactory;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;

class InstallData implements InstallDataInterface
{
  private $eavSetupFactory;
  private $customerSetupFactory;

  public function __construct(
    EavSetupFactory $eavSetupFactory,
    CustomerSetupFactory $customerSetupFactory
    )
    {
      $this->eavSetupFactory = $eavSetupFactory;
      $this->customerSetupFactory = $customerSetupFactory;
    }

    public function install(
      ModuleDataSetupInterface $setup,
      ModuleContextInterface $context
    ) {
      $setup->startSetup();

      $eavSetup = $this->eavSetupFactory->create(('setup' => $setup));
      $customerSetup = $this->customerSetupFactory->create(('setup' => $setup));

      $attributeCode = 'customer_logos';

      $customerSetup->addAttribute(
        MagentoCustomerModelCustomer::ENTITY,
        $attributeCode,
        (
          'type' => 'varchar',
          'input' => 'file',
          'label' => 'Customer Logos',
          'source' => '',
          'required' => false,
          'visible' => true,
          'position' => 200,
          'system' => false,
          'backend' => ''
        )
      );

      // used this attribute in the following forms
      $attribute = $customerSetup->getEavConfig()
      ->getAttribute(MagentoCustomerModelCustomer::ENTITY, $attributeCode)
      ->addData(
        ('used_in_forms' => (
          'adminhtml_customer'
        )
      ));

      $attribute->save();
      $setup->endSetup();
    }
  }

magento2.3 – Address Options > Number of Lines in a Street Address

I am experiencing a problem in my magento 2 store.
I cannot set the line quantity in Settings> Client Configuration> Name and Address Options> Number of Lines in Address
I can put any value 1, 2,3 or 4
Magento always returns only two lines as shown below.
This error occurs in all places where the customer’s address is placed, either in the admin, in / customer or at the checkout
All the basic procedures for cleaning caches, compilation and deploys were done, I even rebooted the server but nothing worked.
Environment:
PHP 7.3
Magento 2.3.6
Opcache
Redis
MYSQL

Magento is in developer mode,
none
exception for this error.

I did a search for street in my database and got these results in the table eav_attribute.

I just recently migrate the data from my magento 1 store and I believe something is corrupted in my database.

Magento Error

eav_attribute

eav_attribute

magento2.3 – Magento2 – How can we exend V1/products?searchCriteria to remove outofstock from the result

We are using Magento 2.3.5

When calling the V1/products?searchCriteria , the result contains out of stock items too.

We tried the filter option quantity_and_stock_status, but which is not working perfectly.
So is there any option to override the product collection in order to add stock condition with collection?

Tried with afterGetList by adding the stock condition, but the pagination getting wrong.

magento2.3 – How to add new field to invoice and save its value from Rest API call and get its value in Api Call

I want to add new field to invoice table, I have created custom module for that and added new field to invoice table.

Now I want to save the value in this field using Rest API, when i create invoice using API, how to pass the value for this field in API call and what changes should be done to save its value.

I also want to load the value of this field in API response means when I call API to load the invoice data, this field should be there in the response data.