magento2 – Magento 2 : How to set different list.phtml for each category

I want to do like this list.phtml should be different different call in category page. I created custom category layout and assign phtml file for that. But, layered navigation at bottom after product grid.

It should be display same as like 2-column-left layout. How to solve it?

custom layout code :

app/design/frontend/Vendor/CustomTheme/Magento_Theme/page_layout/category_my_custom.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
  <update handle="2columns-left"/>
  <body>
    <referenceContainer name="content">
    <referenceBlock name="category.products">
        <block name="product_list" class="MagentoCatalogBlockProductListProduct">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Magento_Catalog::product/book_list.phtml</argument>
            </action>
        </block>
    </referenceBlock>
    </referenceContainer>
</body>
</layout>

Please help me.

Thanks.

magento2 – Only partial order object in `sales_order_invoice_pay` observer when subtotal is zero

I have an observer for the sales_order_invoice_pay event with the following code.

public function execute(MagentoFrameworkEventObserver $observer) {
  $order = $observer->getEvent()->getInvoice()->getOrder();
  $orderId = $order->getId();
  $incrementId = $order->getIncrementId();
}

This works fine most of the time. However, when the invoiced total is 0 (e.g. because of a coupon), then $order->getId() is empty. $incrementId is still available, but I’m not able to get the associated order either. It seems that the order is only partially set in this case.

Is it possible to get the complete order object in this case, or do I need to use another event? It is not clear to me what’s the difference, because it works if the invoiced total is more than 0. Note that the “Zero Subtotal Checkout” is enabled.

Also, I don’t seem to be able to print / debug these objects. All the suggested variants crash in my case (e.g. $order->debug(), $order->getData(), print_r, var_dump). Any suggestions on how to this are appreciated. I currently use the Psr logger.

database – which table to store data like simple product in Magento2?

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

magento2 – ERROR: Item (MagentoSalesModelOrderInterceptor) with the same ID already exists

I’m using Magento 2.3.4, When I try to run loop to print all value it give me an error, I search but didn’t found what’s the problem.

Exception #0 (Exception): Item (MagentoSalesModelOrderInterceptor) with the same ID “371968” already exists.

        $resourceCollection->addFieldToSelect(
            array(
                'increment_id',
                'grand_total',
                'tax_amount',
                'shipping_description',
                'shipping_amount',
                'coupon_code'
            )
        )->join(
            'sales_order_item',
            'sales_order_item.order_id = main_table.entity_id',
            array(
                'sku' => 'sales_order_item.sku',
                'qty_ordered' => 'sales_order_item.qty_ordered',
                'item_price' => 'sales_order_item.original_price',
                'item_discount_amount' => 'sales_order_item.discount_amount',
                'item_tax_amount' => 'sales_order_item.tax_amount'
            )
        )->join(
            'sales_shipment_track',
            'sales_shipment_track.order_id = main_table.entity_id',
            array(
                'track_number' => 'sales_shipment_track.track_number'
            )
        );

        if(!empty($data('sku'))){
            foreach($skus as $sku){
                $resourceCollection->addAttributeToFilter('sales_order_item.sku', array('like' => '%'.$sku.'%'));
            }
        }

        $resourceCollection->addFieldToFilter(
            'main_table.created_at', 
            array(
                'from'=>$data('fromDate'),
                'to'=>$data('toDate')
            )
        );

magento2 – Override Custom Theme Layout File with one in Module?

I have a custom layout file mytheme/default/magento_theme/layout/custom_cms_name.xml

I need to override with a theme file from my custom module:
/companyname/modulename/frontend/layout/

I tested and “/companyname/modulename/frontend/layout/cms_page_view_id_idhere.xml” works so I know the module is working but /companyname/modulename/frontend/layout/custom_cms_name.xml does not work.

What naming convention can I use within my module to override custom layout form my theme ??

magento2 – My custom Grid is not showing on adminside. Magento 2

I’ve made Grid many times n its working fine every time but dont know what happend this time it looks like
enter image description here

where you can see the my custom button is showing properly which comes from the Ui component but grid is not shown my files are

di.xml

<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="marketplace_listing_data_source" xsi:type="string">AppthaMarketplaceModelResourceModelMarketplaceGridCollection</item>
            </argument>
        </arguments>
    </type>

ControllerAdminhtmlIndex

<?php
namespace AppthaMarketplaceControllerAdminhtmlIndex;

class Index extends MagentoBackendAppAction
{
   
    protected $resultPageFactory;

   
    public function __construct(
        MagentoBackendAppActionContext $context,
        MagentoFrameworkRegistry $coreRegistry,
        MagentoFrameworkViewResultPageFactory $resultPageFactory
    ) {
        $this->resultPageFactory = $resultPageFactory;
        parent::__construct($context, $coreRegistry);
    }

   
    public function execute()
    {

        $resultPage = $this->resultPageFactory->create();
        $this->initPage($resultPage)->getConfig()->getTitle()->prepend(__('Registration'));
        return $resultPage;
    }
    protected function initPage($resultPage)
    {
         $resultPage->setActiveMenu('Apptha_Marketplace::registration')
             ->addBreadcrumb(__('Apptha'), __('Apptha'))
             ->addBreadcrumb(__('Registration'), __('Registration'));

         return $resultPage;
    }

 
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Apptha_Marketplace::registration');
    }
}

viewadminhtmllayoutmarketplace_index_edit.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="content">
            <uiComponent name="marketplace_edit"/>
        </referenceContainer>
     
    </body>
</page>

viewadminhtmlui_componentmarketplace_edit.xml

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">marketplace_edit.marketplace_data_source</item>
            <item name="deps" xsi:type="string">marketplace_edit.marketplace_data_source</item>
        </item>
        <item name="label" xsi:type="string" translate="true">Manage Post</item>
         <item name="config" xsi:type="array">
            <item name="dataScope" xsi:type="string">data</item>
            <item name="namespace" xsi:type="string">marketplace_edit</item>
        </item>
    </argument>
    <dataSource name="marketplace_data_source"
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">AapthaMarketplaceModelMarketplaceDataProvider</argument>
            <argument name="name" xsi:type="string">marketplace_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">register_id</argument>
            <argument name="requestFieldName" xsi:type="string">id</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="submit_url" xsi:type="url" path="marketplace/index/save"/>
                </item>
            </argument>
        </argument>
        <argument name="data" xsi:type="array">
            <item name="js_config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
            </item>
        </argument>
    </dataSource>
    <fieldset name="general">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string"/>
            </item>
        </argument>
        <field name="id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">false</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">marketplace</item>
                </item>
            </argument>
        </field>
        <field name="name">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string">Name:</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">marketplace</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                </item>
            </argument>
        </field>
        <field name="p_number">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string">Phone Number:</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="dataType" xsi:type="string">textarea</item>
                    <item name="formElement" xsi:type="string">textarea</item>
                    <item name="source" xsi:type="string">marketplace</item>
                </item>
            </argument>
        </field>        
     </fieldset>
 </form>

what is the issue why it is not showing Grid? any help would be really appreciated Thanks

magento2 – Error magento 2.3.3-p1 with Smile ElasticsuiteCore

During magento upgrade to 2.3.5-p1, after doing a composer install this happened when I tried to do any command i.e:

magento setup:upgrade

The error on terminal:

Class SmileElasticsuiteCoreModelSearchRequestRelevanceConfigResolverContainers does not exist#0 /var/www/html/vendor/magento/framework/Code/Reader/ClassReader.php(19): ReflectionClass->__construct('Smile\Elasticsu...')
#1 /var/www/html/vendor/magento/framework/ObjectManager/Definition/Runtime.php(49): MagentoFrameworkCodeReaderClassReader->getConstructor('Smile\Elasticsu...')
#2 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(48): MagentoFrameworkObjectManagerDefinitionRuntime->getParameters('Smile\Elasticsu...')
#3 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(70): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->create('Smile\Elasticsu...')
#4 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(196): MagentoFrameworkObjectManagerObjectManager->get('Smile\Elasticsu...')
#5 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(172): MagentoFrameworkObjectManagerFactoryAbstractFactory->parseArray(Array)
#6 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgument(Array, NULL, Array, 'scopeResolvers', 'Magento\Framewo...')
#7 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgumentsInRuntime('Magento\Framewo...', Array, Array)
#8 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(59): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->_resolveArguments('Magento\Framewo...', Array, Array)
#9 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(70): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->create('Magento\Framewo...')
#10 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(160): MagentoFrameworkObjectManagerObjectManager->get('Magento\Framewo...')
#11 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgument(Array, 'Magento\Framewo...', NULL, 'scopeResolverPo...', 'Magento\Framewo...')
#12 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgumentsInRuntime('Magento\Framewo...', Array, Array)
#13 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(59): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->_resolveArguments('Magento\Framewo...', Array, Array)
#14 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(70): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->create('Magento\Framewo...')
#15 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(160): MagentoFrameworkObjectManagerObjectManager->get('Magento\Framewo...')
#16 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgument(Array, 'Magento\Framewo...', NULL, 'scopeCodeResolv...', 'Magento\Framewo...')
#17 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgumentsInRuntime('Magento\Framewo...', Array, Array)
#18 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(59): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->_resolveArguments('Magento\Framewo...', Array, Array)
#19 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(70): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->create('Magento\Framewo...')
#20 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(160): MagentoFrameworkObjectManagerObjectManager->get('Magento\Framewo...')
#21 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgument(Array, 'Magento\Framewo...', NULL, 'scopeConfig', 'Magento\Develop...')
#22 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgumentsInRuntime('Magento\Develop...', Array, Array)
#23 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(59): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->_resolveArguments('Magento\Develop...', Array, Array)
#24 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(70): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->create('Magento\Develop...')
#25 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(196): MagentoFrameworkObjectManagerObjectManager->get('Magento\Develop...')
#26 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(172): MagentoFrameworkObjectManagerFactoryAbstractFactory->parseArray(Array)
#27 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgument(Array, NULL, Array, 'handlers', 'SummaSolutions\...')
#28 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgumentsInRuntime('SummaSolutions\...', Array, Array)
#29 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(59): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->_resolveArguments('SummaSolutions\...', Array, Array)
#30 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(70): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->create('SummaSolutions\...')
#31 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(160): MagentoFrameworkObjectManagerObjectManager->get('SummaSolutions\...')
#32 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgument(Array, 'Psr\Log\LoggerI...', NULL, 'logger', 'Magento\Framewo...')
#33 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgumentsInRuntime('Magento\Framewo...', Array, Array)
#34 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(59): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->_resolveArguments('Magento\Framewo...', Array, Array)
#35 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(70): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->create('Magento\Framewo...')
#36 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(160): MagentoFrameworkObjectManagerObjectManager->get('Magento\Framewo...')
#37 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgument(Array, 'Magento\Framewo...', NULL, 'logger', 'Magento\Framewo...')
#38 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): MagentoFrameworkObjectManagerFactoryAbstractFactory->resolveArgumentsInRuntime('Magento\Framewo...', Array, Array)
#39 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(59): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->_resolveArguments('Magento\Framewo...', Array, Array)
#40 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(56): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->create('Magento\Framewo...', Array)
#41 /var/www/html/vendor/magento/framework/App/Cache/Frontend/Factory.php(197): MagentoFrameworkObjectManagerObjectManager->create('Magento\Framewo...', Array)
#42 /var/www/html/vendor/magento/framework/App/Cache/Frontend/Factory.php(161): MagentoFrameworkAppCacheFrontendFactory->_applyDecorators(Object(MagentoFrameworkCacheFrontendDecoratorTagScope))
#43 /var/www/html/vendor/magento/framework/App/Cache/Frontend/Pool.php(67): MagentoFrameworkAppCacheFrontendFactory->create(Array)
#44 /var/www/html/vendor/magento/framework/App/Cache/Frontend/Pool.php(146): MagentoFrameworkAppCacheFrontendPool->_initialize()
#45 /var/www/html/vendor/magento/framework/App/Cache.php(38): MagentoFrameworkAppCacheFrontendPool->get('default')
#46 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(116): MagentoFrameworkAppCache->__construct(Object(MagentoFrameworkAppCacheFrontendPool))
#47 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(66): MagentoFrameworkObjectManagerFactoryAbstractFactory->createObject('Magento\Framewo...', Array)
#48 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(70): MagentoFrameworkObjectManagerFactoryDynamicDeveloper->create('Magento\Framewo...')
#49 /var/www/html/vendor/magento/framework/App/Cache/Proxy.php(44): MagentoFrameworkObjectManagerObjectManager->get('Magento\Framewo...')
#50 /var/www/html/vendor/magento/framework/App/Cache/Proxy.php(67): MagentoFrameworkAppCacheProxy->_getCache()
#51 /var/www/html/vendor/magento/framework/App/ProductMetadata.php(80): MagentoFrameworkAppCacheProxy->load('mage-version')
#52 /var/www/html/vendor/magento/framework/Console/Cli.php(92): MagentoFrameworkAppProductMetadata->getVersion()
#53 /var/www/html/bin/magento(22): MagentoFrameworkConsoleCli->__construct('Magento CLI')
#54 {main}

magento2 – Magento 2 Persistence Lifetime purposer?

I would like to know the use of Persistence Lifetime (seconds) by default value 3153600000 seconds (100 years).

For example if we set 10 Sec from the admin end, is that will effect on cart items those are associated to the customer? How do I have to test it on local (server) & How it works.

I assume after lifetime is expired the cart items will be cleared to the registered users.

Could you please clarify me if anything wrong understand.

Thanks in advance.

magento2 – Unable to resolve the source file for ‘…Magento_Customer/js/zxcvbn.js.map’

I’m running Magento 2.4.0 in developer mode with server-side compilation using PHP Less library.

Console is showing this error in every page:

DevTools failed to load SourceMap: Could not load content for https://example.com/pub/static/version1600339825/frontend/Example/default/en_US/Magento_Customer/js/zxcvbn.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

I tried to access to https://example.com/pub/static/version1600339825/frontend/Example/default/en_US/Magento_Customer/js/zxcvbn.js.map through the browser and it says:

Unable to resolve the source file for 'frontend/Example/default/en_US/Magento_Customer/js/zxcvbn.js.map'
<pre>#1 MagentoFrameworkAppStaticResource->launch() called at (vendor/magento/framework/App/Bootstrap.php:263)
#2 MagentoFrameworkAppBootstrap->run() called at (pub/static.php:13)
</pre>

I checked also the file https://example.com/pub/static/version1600339825/frontend/Example/default/en_US/Magento_Customer/js/zxcvbn.js and it exists.


What I tried

I thought the error was generated by a file merging so I tried to exclude zxcvbn.js from it adding this row in my theme etc/view.xml:

<item type="file">Magento_Customer::js/zxcvbn.js</item> <!-- It was already present -->
<item type="file">Magento_Customer::js/zxcvbn.min.js</item>
<item type="file">Magento_Customer::js/zxcvbn.js.map</item>

but it didn’t work.

Any ideas?

magento2 – URI is not valid and cannot be converted into a string

I’m struggling with an error that is thrown in the debug.log. The problem is that multiple indexers are not updated allthough the cronjobs are running.

Re-indexing by CLI is working properly on all indexers but that cannot be the solution.

The debug.log

(2020-09-17 05:25:12) main.ERROR: Cron Job indexer_reindex_all_invalid has an error: URI is not valid and cannot be converted into a string. Statistics: {"sum":0,"count":1,"realmem":0,"emalloc":0,"realmem_start":146800640,"emalloc_start":143814352} () ()
(2020-09-17 05:25:12) main.CRITICAL: URI is not valid and cannot be converted into a string {"exception":"(object) (Laminas\Uri\Exception\InvalidUriException(code: 0): URI is not valid and cannot be converted into a string at /PATH/web/vendor/laminas/laminas-uri/src/Uri.php:363)"} ()

I took a look at the specified line but it’s just the function that throws the exception. How can i find the ‘url’ that is causing the problem?

Config:

  • Magento 2.3.5.-p1
  • PHP 7.3-Stable

Thanks