magento2.3 – magento 2.3 observers on product attributes save/changes

on my magento 2.3 I need to detect when a particular product attribute is updated in order to change the product price. Changing the product attribute via backend is no big deal: I simply put an observer on the catalog_product_save_after event and check my current attribute value against $product->getOrigData('attribute_code') to see if it’s changed.

The problemi is: when the attribute is imported via csv import feature, that observer is not called. Instead, the catalog_product_import_bunch_save_after event is called. But here I have no way of retrieving the original value of the attribute (because it is called after the save) and the event catalog_product_import_bunch_save_before (that would hold the original data) doesn’t exist.

So now my question is: how can I get the original data for my attribute during the csv import? If I can’t with the observer I’m using, which observer/plugin should I use?

Thanks

magento2.3 – How do i get the order ID and Order Subtotal in the credit memo page?

Im currently trying to write a piece of code that refunds an order and attach it to the “refund” button in the credit memo page using the “sales_order_payment_refund” event.

But, right now, I want to be able to get Order_ID and Order_Subtotal from the credit memo page of the order I have opened to proceed, how can I retrieve those 2?

magento2.3 – How to use grouped product attributes for simple products in layered navigation

I am working on a chemical catalog and I have created grouped products to add attributes like molecular weigt, CAS-Number and other chemical data. These data are all the same for my simple products.
In the layered navigation the grouped products are displayed with its attributes.
What I want now is, that when I click on the layered navigation option, my simple products are displayed too. Untill now, I see only my grouped product.

Therefore my question:
Is there a way to use my grouped attributes to select also my simple products?

Thanks Chris

magento2.3 – Type Error occurred when creating object Magento 2

I have created custom module and it’s working fine in Dev, but it’s not working on Production. It’s throwing Type error.

Type Error occurred when creating object:
TinyProductCustomizationModelResourceModelProductCollectionInterceptor,
Argument 5 passed to
TinyProductCustomizationModelResourceModelProductCollectionInterceptor::__construct()
must implement interface MagentoFrameworkDBAdapterAdapterInterface
or be null, string given, called in
/var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php
on line 121 () () (2021-01-11 10:11:47) report.CRITICAL: Type Error
occurred when creating object:
TinyProductCustomizationModelResourceModelProductCollectionInterceptor
() ()

My collection file as below

<?php

namespace TinyProductCustomizationModelResourceModelProduct;

use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;

class Collection extends AbstractCollection
{

    protected $_idFieldName = 'id';

    protected function _construct()
    {
        $this->_init(
            'TinyProductCustomizationModelProduct',
            'TinyProductCustomizationModelResourceModelProduct'
        );
        parent::_construct();
    }

}

and di.xml

<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="tiny_grid_data_source" xsi:type="string">TinyProductCustomizationModelResourceModelProductCollection</item>
            </argument>
        </arguments>
    </type>
    <virtualType name="TinyProductCustomizationModelResourceModelProductCollection" type="MagentoFrameworkViewElementUiComponentDataProviderSearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">tiny_pro</argument>
            <argument name="resourceModel" xsi:type="string">TinyProductCustomizationModelResourceModelProduct</argument>
        </arguments>
    </virtualType>

Can you please help me on this?

magento2.3 – Anybody know the Reference block name for the Footer->Miscellaneous HTML

Within Content->Design->Configuration->Theme->Footer->Miscellaneous HTML I have added some HTML and it works correctly

However, I use a popup and it also displays at the bottom of the popup window

Through the pop-ups Layout.xml I would like to remove the Miscellaneous HTML using something like

<referenceBlock name="XXXXXXXXXX" remove="true"/>

Can anyone please give me the referenceBlock name for the Miscellaneous HTML?

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 – 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 – 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();
    }
  }