magento2.4.1 – Magento 2.4.1: How to resolve [Report Only] Refused to load the font ” because it violates the following Content Security Policy directive:

With a custom module, I am trying to resolve the content security policy warnings. I’m not sure under which policy should I place the URLS reported by Refused to connect to.

Pleae guide me as to how it needs to handled in csp_whitelist.xml. Below is a real example from our store.

[Report Only] Refused to load the font '<URL>' because it violates the following Content Security Policy directive: "font-src *.cloudflare.com *.bootstrapcdn.com 'unsafe-inline' data: api.stripe.com js.stripe.com m.stripe.com x.klarnacdn.net klarna.com na.playground.klarnaevt.com eu.playground.klarnaevt.com klarna-payments-eu.playground.klarna.com klarna-payments-na.playground.klarna.com maxcdn.bootstrapcdn.com 'self' 'unsafe-inline'".

Below is my code in csp_whitelist.xml

<policy id="font-src">
    <values>
        <value id="cloudflare" type="host">*.cloudflare.com</value>
        <value id="maxcdn" type="host">*.bootstrapcdn.com</value>
        <value id="data" type="host">'unsafe-inline' data:</value>
    </values>
</policy>

How to set image for product on catalog_product_save_after event in magento 2?

I am able to set quantity after product save but not able to figure out how to set a product image on catalog_product_save_after event. Any help

admin – Magento 2.1.7 “Ghost” exports triggered by magento?

In the last few days, my Magento instance started some exports automatically without any of the admin users triggering it.

Background
I rewrote the export logic to make it run in the background, so if an admin user starts an export via the admin ui, a value is written into the config database. Then a cronjob runs the export task in the background and sends an email, when the job is done. This was done because we have over 20000 products which the browser couldn’t handle.
The original export logic is still there, the only difference is that the export isn’t done in the browser, it’s the done the background.

The last few days, I got some random emails that the export job is done, but no one was triggering it so we have two possibilities:

1) someone has access to the admin ui and starts the exports without me knowing it:
I checked the access logs and admin_sessions on the database, there were no “sketchy” sessions and no admin/export urls called in the time the exports were happening, therefor i don’t think that’s the cases

2) magento starts the exports by itself: is this possible? is there any (cron)job or task, the starts exports in the magento instance? I run the normal cron jobs, so nothing special there.

Any ideas what I’m missing? Where are those exports coming from?

topmenu – How to override top menu and add icon in Magento 2?

Stack Exchange Network


Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

How to get parent SKU from associated simple product in Magento 1.9?

Here is my code, but it is only generating the simple product SKU where I want to get it for the configurable product page also. I used it to restrict a block on a simple and configurable product page.

$_cId = 0;

if(Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customerData = Mage::getSingleton('customer/session')->getCustomer();
    $_cId = $customerData->getId();
}

$orderItems = Mage::getResourceModel('sales/order_item_collection')
    ->addFieldToFilter('sku', $this->getProductInfo()->getSku())
    ->toArray(array('order_id'));

$orderIds = array_unique(array_map(
    function($orderItem) {
        return $orderItem('order_id');
    },
    $orderItems('items')));

$orderCollection = Mage::getResourceModel('sales/order_collection')
    ->addFieldToFilter('entity_id',   array('in'  => $orderIds))
    ->addFieldToFilter('customer_id', array('eq' => $_cId));
$orderCollection->getSelect()->group('customer_id');

$customerCollection = Mage::getModel('customer/customer')->getCollection()
    ->addFieldToFilter('entity_id', array('in' => $orderCollection->getColumnValues('customer_id')));

foreach ($customerCollection as $customer) {
    // Code
}

magento2 – Magento 2 API usage internally

i am doing several custom modules in Magento 2.

It is a good practice do all the thing orientated to API (thinking in be consume for an mobile app for example ) and also use those api internally in the view model?

Or should i create a controller for return json to the view model and API just for external calls?

For example, i want to show a popup with a list of products using KOjs.

should i use a controller to return the products of that AJAX call o can i use the magento 2 API “rest/V1/products”

Magento2: theme builder – Magento Stack Exchange

I am looking for a solution with which I can build a custom template for Magento 2. I’ve seen a few extensions, but these are more of a page builder than a theme builder.

Can anyone recommend a solution with which I will be able to build a template from scratch?

magento2 – magento 2 getproduct colelciton with catalogsearch leftnav

I want get product collection with catalog search left block
i tried this way

$leftNavBlock = $layout->getBlock('catalogsearch.leftnav');
 $list('options') = $leftNavBlock->getLayer()->getProductCollection()->getFacetedData($code);

but here not getting all options getting only some
brand having
tayota,hundai,honda,nissan,lexus. but by using above code tayota,hundai,honda,lexus.
in search result page it showing all options which assigned by productsenter image description here

enter image description here

magento2.4.1 – Magento 2.4.1: We cannot retrieve payment information object instance

The store has recently been upgraded to Magento 2.4.1. When trying to move to payment methods page from checkout by clicking the next button, message “We cannot retrieve payment information object instance” is displayed. I don’t seem to find any setting that I can check in the admin to fix this. Please advise what can I try to fix it?