magento2 – Magento 2 extension manager 500 error

I’m trying to install extensions using the extension manager, I have my access keys set, when entering the extension manager page, it’s always stuck on “Please wait”. The console log shows the below:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)
angular.js:533 Possibly unhandled rejection: {"data":"","status":500,"config":{"method":"GET","transformRequest":(null),"transformResponse":(null),"jsonpCallbackParam":"callback","url":"index.php/extensionGrid/extensions","headers":{"Accept":"application/json, text/plain, */*","Cache-Control":"no-cache, no-store, must-revalidate","Pragma":"no-cache","Expires":0}},"statusText":"Internal Server Error","xhrStatus":"complete"}
(anonymous) @ angular.js:533
/setup/index.php/extensionGrid/extensions:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)
angular.js:533 Possibly unhandled rejection: {"data":"","status":500,"config":{"method":"GET","transformRequest":(null),"transformResponse":(null),"jsonpCallbackParam":"callback","url":"index.php/extensionGrid/extensions","headers":{"Accept":"application/json, text/plain, */*","Cache-Control":"no-cache, no-store, must-revalidate","Pragma":"no-cache","Expires":0}},"statusText":"Internal Server Error","xhrStatus":"complete"}
(anonymous) @ angular.js:533
angular.js:12571 POST https://website.com/setup/index.php/session/prolong 500 (Internal Server Error)
(anonymous) @ angular.js:12571
n @ angular.js:11748
(anonymous) @ angular.js:11263
(anonymous) @ angular.js:6988
$digest @ angular.js:8414
$apply @ angular.js:8817
(anonymous) @ angular.js:12941
23angular.js:12571 GET https://website.com/setup/index.php/session/unlogin 401 (Unauthorized)

magento2 – Magento 2 – How to allow livereload in CSP whitelist?

I had the same issue, and fixed it with the following:

Create a plugin

app/code/Company/Csp/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoCspModelCollectorCspWhitelistXmlCollector">
        <plugin name="cspAddLivereload" type="MyCompanyCspPluginCsp" sortOrder="1" disabled="false"/>
    </type>
</config>

app/code/Company/Csp/Plugin/Csp.php

<?php

namespace CompanyCspPlugin;

use MagentoCspModelCollectorCspWhitelistXmlCollector;
use MagentoCspModelPolicyFetchPolicy;

class Csp
{

    /**
     * @inheritDoc
     */
    public function afterCollect(CspWhitelistXmlCollector $cspWhitelistXmlCollector, $defaultPolicies = ()): array
    {
        $defaultPolicies() = new FetchPolicy(
            "connect-src",
            false,
            ("www.company.de:35729", "ws://www.company.de:35729"),
            (),
            false,
            false,
            false,
            (),
            (),
            false,
            false
        );
        $defaultPolicies() = new FetchPolicy(
            "script-src",
            false,
            ("www.company.de:35729"),
            (),
            false,
            false,
            false,
            (),
            (),
            false,
            false
        );
        return $defaultPolicies;
    }
}

This adds the specified policies to the Csp programatically.

I have changed some things to work with your URL, so it’s not fully tested

magento2 – update product websites on magento 2 programmatically

I have come across posts to update products websites programmatically for Magento 1. However, I do not find the same for Magento 2. Ideally, a command would really be useful.

Can somebody help with writing a command in M2 to add/remove websites to a product and ideally to a list of product ids

magento2 – Magento 2.3.5-p2 Image Uploader not Working

When I attempt to upload an image to Magento 2, I click the option in the toolbar and when I attempt to browse for the file I am taken to a blank white screen and do not see any browser information to choose my file. I recently attempted to upgrade from Magento 2.3.5-p1 to 2.4. However when I realized I needed ElasticSearch 7 I then downgraded to 2.3.5-p2. I am not sure if this is related to my problem or no.

magento2.3 – Magento 2.4.0 upgrade from Magento 2.3.5 not updating

when i upgrade to 2.4.0 from admin area. i get all green check mark, it goes through the next step, I skip the backup process. next step it goes through normal process after couple minutes into it, it shows success! but the magento version is still 2.3.5. not updating. any idea ?

magento2 – Is there any way to get all Applied Discount (for cart rules and coupons) line items in cart/order in Magento 2?

I need to show all cart/order discounts in the following manner:

Subtotal                              ----------- 100.00

CHRISTMAS10 (Christmas Sale 10 % off) ----------- -10.00
CHDLL1242DK (Coupon Redeemed)         ----------- -20.00

Grand Total                           -----------  70.00

Magento 2 store only the coupon_code and the applied_rule_ids, but not the discount amount for specific rule and discount description.

What would the best way to achieve this? (also if there is any module available, please suggest)

magento2 – Properly add new columns to sales order grid in Magento 2

I created a module to add 2 columns in sales grid, shipping_information and tracking number.
The columns appears but when I tried to filter by Order ID in admin order page, example with 973, I got this error

main.CRITICAL: Item (MagentoFrameworkViewElementUiComponentDataProviderDocumentInterceptor) with the same ID "6245" already exists. {"exception":"(object) (Exception(code: 0): Item (Magento\Framework\View\Element\UiComponent\DataProvider\Document\Interceptor) with the same ID "6245" already exists. at /home/xxxx/public_html/vendor/magento/framework/Data/Collection.php:404)"} 

Also this error

Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous

But when I tried with another ID, the error disappear

In Vendor/Module/Model/ResourceModel/Order/Grid/Collection.php

namespace WetagAdditionalOrderFieldsModelResourceModelOrderGrid;

use MagentoFrameworkDataCollectionDbFetchStrategyInterface as FetchStrategy;
use MagentoFrameworkDataCollectionEntityFactoryInterface as EntityFactory;
use MagentoFrameworkEventManagerInterface as EventManager;
use MagentoSalesModelResourceModelOrderGridCollection as OriginalCollection;
use PsrLogLoggerInterface as Logger;

/**
 * Order grid extended collection
 */
class Collection extends OriginalCollection
{
    protected $helper;

    public function __construct(
        EntityFactory $entityFactory,
        Logger $logger,
        FetchStrategy $fetchStrategy,
        EventManager $eventManager,
        $mainTable = 'sales_order_grid',
        $resourceModel = MagentoSalesModelResourceModelOrder::class
    )
    {
        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
    }

protected function _renderFiltersBefore()
{
    $joinTable = $this->getTable('sales_order');
    $joinTable_track = $this->getTable('sales_shipment_track');
    
    
    $this->getSelect()->joinLeft($joinTable, 'main_table.entity_id = sales_order.entity_id', ('shipping_information'))->distinct();
    $this->getSelect()->joinLeft($joinTable_track, 'sales_order.entity_id = sales_shipment_track.order_id', ('track_number'))->distinct();
    parent::_renderFiltersBefore();
}
protected function _initSelect()  {

    $this->addFilterToMap('increment_id', 'main_table.increment_id');
    $this->addFilterToMap('status', 'main_table.status');
    parent::_initSelect();
  
   return $this; 

}
}

In Vendor/Module/etc/di.xml

<?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="sales_order_grid_data_source" xsi:type="string">VendorModuleModelResourceModelOrderGridCollection</item>
            </argument>
        </arguments>
    </type>
    <type name="VendorModuleModelResourceModelOrderGridCollection">
        <arguments>
            <argument name="mainTable" xsi:type="string">sales_order_grid</argument>
            <argument name="resourceModel" xsi:type="string">MagentoSalesModelResourceModelOrder</argument>
        </arguments>
      </type>
</config>

In etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="1.0.0">
       <sequence>
           <module name="Magento_sales" />
       </sequence>
    </module>
</config>

In Vendor/Module/view/adminhtml/ui_component/sales_order_grid.xml

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="sales_order_columns">
    
        <column name="shipping_information">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true">Shipping method</item>
                </item>
            </argument>
        </column>
        <column name="track_number">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true">Tracking number</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

I like to use the field shipping_information in order_sales_grid table, I didn’t get it without making a left join, I like to select this field without join

magento2.3.5 – Magento 2 How to extend Recently Viewed Products widget

I want to extend Recently Viewed Products widget so I can add review attribute.
After creating this file: Vendor/MyModule/view/frontend/ui_component/widget_recently_viewed.xml:

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="widget_columns">
        <column name="review" component="Vendor_MyModule/js/product/summary" sortOrder="4" displayArea="details-area">
            <settings>
                <label translate="true">Review</label>
                <bodyTmpl>Vendor_MyModule/product/summary</bodyTmpl>
            </settings>
        </column>
    </columns>
</listing>

and clear cache, I got this error in browser console:

Uncaught ReferenceError: Unable to process binding "if: function(){return isMsrpApplicable($row()) }"
Message: isMsrpApplicable is not defined

How to properly extend this widget?

magento2 – How to load js file first in Magento 2

I’m using Magento 2 and I have a js file that was called like this:

default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
      <referenceContainer name="after.body.start">
          <block class="VendorModuleBlockAjaxLoginJs" template="Vendor_Module::login-ajax.phtml" name="login.ajax" as="login.ajax" before="head.components" ifconfig="loginpopup/general/enabled" />
      </referenceContainer>
    </body>
</page>

login-ajax.phtml

<script type="text/x-magento-init">
{
    "*": {
        "vm/loginajax"    : <?php echo $block->getJsOptions(); ?>
    }
} 

requirejs-config.js

var config = {
    map: {
        '*': {
            'vm/loginajax': 'Vendor_Module/js/login-ajax'
        }
    }
};

Vendor_Module/js/login-ajax

define((
    'jquery',
    'mage/translate',
    'jquery/ui',
    'mage/validation/validation',
    'vm/mycustom'
), function ($, $t) 

the js file size is 3KB , i noticed the js file is rendered not at the very beginning, how can i set the priority so this js file will load first?

How to export products in Magento 2 in XML format

I am trying to export products from Magento in an XML format rather than CSV. I know there are modules that can do this, but I am trying to learn to do things in Magento 2 for myself. Was wondering if there was code I could add to the backend to add XML as an export format?