magento2 – Get images by selected color on Product View page

I want to get the Images Array from the specific color that is selected by the client, in the PRODUCT VIEW PAGE.

So i found something on

templates/product/view/gallery.phtml

I found $block->getGalleryImages() But I couldn’t do what i wanted, maybe i’m using in the wrong way, or i’m on the wrong file.

Any help is appreciated…

magento2 – Magento 2 is it possible to sell not in stock products?

You can enable backorder. This is Magento feature where you can allow the user to purchase the product even it is out of stock in the backend. But product is out of stock this will not display in thefrontend, product will always display in stock in the frontend. If you want to display out of stock status when product inventory is negative then you need to make customization.

You can use below tutorial to enable the backorder.
https://docs.magento.com/user-guide/catalog/inventory-backorders.html
https://www.simicart.com/blog/magento-backorders/

Hope this will help you.

magento2 – Magento 2.3.4 – Server temp folder gets full because of SQL queries

I am using Magento 2.3.4, and the server temp folder gets full because of SQL queries. I am looking for someone who can optimize SQL server and queries from Magento 2. The below error appears when the site crashes.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

SQLSTATE(HY000): General error: 1021 Disk full (/dev/shm/#sql_2e1b28_7.MAI); waiting for someone to free some space… (errno: 28 “No space left on device”), query was: SELECT main_table.* FROM eav_attribute AS main_table
INNER JOIN eav_entity_type AS entity_type ON main_table.entity_type_id = entity_type.entity_type_id
LEFT JOIN eav_entity_attribute ON main_table.attribute_id = eav_entity_attribute.attribute_id
INNER JOIN catalog_eav_attribute AS additional_table ON main_table.attribute_id = additional_table.attribute_id WHERE (entity_type_code = ‘catalog_product’) AND ((additional_table.is_used_in_grid = 1)) GROUP BY main_table.attribute_id

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Can someone help me

magento2 – System upgrade from the admin panel

Magento 2 System upgrade from the admin panel shows the below message:

magento/product-community-edition 2.4.0 requires php ~7.3.0||~7.4.0 -> your PHP version (7.0.33) does not satisfy that

I have used the command to enable the PHP version 7.4 sudo a2enmod php7.4 and then sudo service apache2 restart now doing the readiness check again shows the above error and if I disable the current PHP version which is 7.0 sudo a2dismod php7.0 and then the admin panel will not load with PHP7.4.

Any solution?

magento2 – Magento 2 delete Meta Name Meta Title Meta Description ALL products

Magento 2 delete Meta Name Meta Title Meta Description ALL products

Please can someone let me know if its possible to delete the Meta Values for all products in my store

These were added during import and we want to remove them as we want to use extension to auto generate these values.

Is there anything that can be done via MYSQL to quickly remove all the entries for them.

I dont want to export all products and then update with blank it will take forever as there are 30000 + products

magento2 – Magento 2 Filter admin grid with custom columns

I have a custom table that is assigned to multiple store so i do have another table for their relationship. my problem now is i want to filter my custom table by store in the admin grid. i was able to display it by manipulating my data provider. but my filter is not working because mui/index/render is trying filtering store_id in the main_table which does not exist.

i getting an error in the exeption.log “Unknown column ‘store_id’ in ‘where clause’, query was: SELECT COUNT(*) FROM my_table AS main_table WHERE (store_id = ‘1’)”

DataProvider.php

 public function __construct(
    $name,
    $primaryFieldName,
    $requestFieldName,
    MyModuleModelResourceModelfaqsCollection $faqsCollection,
    MagentoFrameworkAppRequestInterface $request,
    MyModuleHelperResource $resourceHelper,
    array $meta = (),
    array $data = ()
){
    $this->collection = $faqsCollection;
    $this->request = $request;
    $this->resourceHelper = $resourceHelper;
    parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
}

public function getData()
{
    if (isset($this->loadedData)) {
        return $this->loadedData;
    }

    $faqsId = $this->request->getParam('faqs_id');
    if($faqsId){ //form data. please dont mind this part
        $faqsCollection = $this->collection->addFieldToFilter('faqs_id', $faqsId);
        foreach ($faqsCollection as $faqs){
            $this->loadedData($faqs->getId()) = $faqs->getData();
        }
    } else { //grid data. here is where i manipulate the data for the grid
        $faqsCollection = $this->collection->toArray();
        $this->loadedData('totalRecords') = $faqsCollection('totalRecords');
        foreach ($faqsCollection('items') as $faqs){
            $faqs('store_id') = $this->resourceHelper->getTopicStores($faqs('topic_id'));
            $this->loadedData('items')() = $faqs;
        }
    }


    return $this->loadedData;
}

then in my faqs_grid.xml ui_component

<dataSource name="faqs_grid_data_source" component="Magento_Ui/js/grid/provider">
    <settings>
        <storageConfig>
            <param name="indexField" xsi:type="string">faqs_id</param>
        </storageConfig>
        <updateUrl path="mui/index/render"/>
    </settings>
    <aclResource>My_Module::faq</aclResource>
    <dataProvider class="MyModuleModelfaqsDataProvider" name="faqs_grid_data_source">
        <settings>
            <requestFieldName>faqs_id</requestFieldName>
            <primaryFieldName>faqs_id</primaryFieldName>
        </settings>
    </dataProvider>
</dataSource>

<listingToolbar name="listing_top">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="sticky" xsi:type="boolean">true</item>
        </item>
    </argument>
    <columnsControls name="columns_controls"/>
    <filters name="listing_filters">
        <argument name="data" xsi:type="array">
            <item name="observers" xsi:type="array">
                <item name="column" xsi:type="string">column</item>
            </item>
        </argument>
        <settings>
            <templates>
                <filters>
                    <select>
                        <param name="template" xsi:type="string">ui/grid/filters/elements/ui-select</param>
                        <param name="component" xsi:type="string">Magento_Ui/js/form/element/ui-select</param>
                    </select>
                </filters>
            </templates>
        </settings>
        <filterSelect name="store_id" provider="${ $.parentName }">
            <settings>
                <captionValue>0</captionValue>
                <options class="MagentoCmsUiComponentListingColumnCmsOptions"/>
                <label translate="true">Store View</label>
                <dataScope>store_id</dataScope>
                <imports>
                    <link name="visible">componentType = column, index = ${ $.index }:visible</link>
                </imports>
            </settings>
        </filterSelect>
    </filters>
    <paging name="listing_paging"/>
</listingToolbar>

<columns name="faq_listing_columns">
    <column name="store_id" class="MagentoStoreUiComponentListingColumnStore">
        <settings>
            <label translate="true">Store View</label>
            <bodyTmpl>ui/grid/cells/html</bodyTmpl>
            <sortable>false</sortable>
        </settings>
    </column>

the displaying is working properly. but i need to find a way to filter it by store_id.

Magento2 Enterprice multicurrency website i want to checkout page country dropdown only india to be set when product purchase like inr

Magento2 Enterprice edition multicurrency website i want to checkout cart page country dropdown only india to be set when product purchase like inr (indian Rupies). so please given me a solution .

magento2 – Child Products appearance for different websites in magento 2.3.2

I have 2 websites “Retail” and “Wholesale”. I am using configurable products on both the sites.
For each configurable products, some child products are to be shown on Retail site and some on Wholesale site.
See https://prnt.sc/um8eyp

Now in frontend when i visit the retail and the wholesale website all the 3 child products are visible there.
In fact, i have selected proper website scope for them.
See https://prnt.sc/um8flv for 50 yards roll products which need to be visible only on wholesale site
See https://prnt.sc/um8fsz for yards product which needs to be visible on retail site.

What is the solution for this?

magento2 – How to check if a product is in stock or out stock?

I am trying to override this controller magentomodule-salesControllerAbstractControllerReorder.php and would like to add an if statement to check if a product is still in stock or no.

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

namespace MagentoSalesControllerAbstractController;

use MagentoFrameworkAppAction;
use MagentoFrameworkRegistry;
use MagentoFrameworkAppActionHttpPostActionInterface;

/**
 * Abstract class for controllers Reorder(Customer) and Reorder(Guest)
 *
 * @package MagentoSalesControllerAbstractController
 */
abstract class Reorder extends ActionAction implements HttpPostActionInterface
{
    /**
     * @var MagentoSalesControllerAbstractControllerOrderLoaderInterface
     */
    protected $orderLoader;

    /**
     * @var Registry
     */
    protected $_coreRegistry;

    /**
     * @param ActionContext $context
     * @param OrderLoaderInterface $orderLoader
     * @param Registry $registry
     */
    public function __construct(
        ActionContext $context,
        OrderLoaderInterface $orderLoader,
        Registry $registry
    ) {
        $this->orderLoader = $orderLoader;
        $this->_coreRegistry = $registry;
        parent::__construct($context);
    }

    /**
     * Action for reorder
     *
     * @return MagentoFrameworkControllerResultInterface
     */
    public function execute()
    {
        $result = $this->orderLoader->load($this->_request);
        if ($result instanceof MagentoFrameworkControllerResultInterface) {
            return $result;
        }
        $order = $this->_coreRegistry->registry('current_order');
        /** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();

        /* @var $cart MagentoCheckoutModelCart */
        $cart = $this->_objectManager->get(MagentoCheckoutModelCart::class);
        $items = $order->getItemsCollection();
        foreach ($items as $item) {
            try {
                $cart->addOrderItem($item);
            } catch (MagentoFrameworkExceptionLocalizedException $e) {
                if ($this->_objectManager->get(MagentoCheckoutModelSession::class)->getUseNotice(true)) {
                    $this->messageManager->addNoticeMessage($e->getMessage());
                } else {
                    $this->messageManager->addErrorMessage($e->getMessage());
                }
                return $resultRedirect->setPath('*/*/history');
            } catch (Exception $e) {
                $this->messageManager->addExceptionMessage(
                    $e,
                    __('We can't add this item to your shopping cart right now.')
                );
                return $resultRedirect->setPath('checkout/cart');
            }
        }

        $cart->save();
        return $resultRedirect->setPath('checkout/cart');
    }
}

this is the line that I want to add the if statement – basically inside the foreach item function.

foreach ($items as $item) {
            try {
                $cart->addOrderItem($item);
            } catch (MagentoFrameworkExceptionLocalizedException $e) {
                if ($this->_objectManager->get(MagentoCheckoutModelSession::class)->getUseNotice(true)) {
                    $this->messageManager->addNoticeMessage($e->getMessage());
                } else {
                    $this->messageManager->addErrorMessage($e->getMessage());
                }
                return $resultRedirect->setPath('*/*/history');
            } catch (Exception $e) {
                $this->messageManager->addExceptionMessage(
                    $e,
                    __('We can't add this item to your shopping cart right now.')
                );
                return $resultRedirect->setPath('checkout/cart');
            }
        }

What I did:

/**
     * @var MagentoSalesControllerAbstractControllerOrderLoaderInterface
     */
    protected $orderLoader;

    /**
     * @var Registry
     */
    protected $_coreRegistry;

    protected $_stockItemRepository;

    /**
     * @param ActionContext $context
     * @param OrderLoaderInterface $orderLoader
     * @param Registry $registry
     */
    public function __construct(
        ActionContext $context,
        OrderLoaderInterface $orderLoader,
        Registry $registry,
        MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
    ) {
        $this->orderLoader = $orderLoader;
        $this->_coreRegistry = $registry;
        $this->_stockItemRepository = $stockItemRepository;
        parent::__construct($context, $orderLoader, $registry);
    }

    /**
     * Action for reorder
     *
     * @return MagentoFrameworkControllerResultInterface
     */
    public function execute()
    {
        $result = $this->orderLoader->load($this->_request);
        if ($result instanceof MagentoFrameworkControllerResultInterface) {
            return $result;
        }
        $order = $this->_coreRegistry->registry('current_order');
        /** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();

        /* @var $cart MagentoCheckoutModelCart */
        $cart = $this->_objectManager->get(MagentoCheckoutModelCart::class);
        $items = $order->getItemsCollection();
        foreach ($items as $item) {
             $_productStock = $this->_stockItemRepository->get($item->getProductId());
             if($_productStock->getIsInStock()) {
            try {
                
                $cart->addOrderItem($item);
    
            } catch (MagentoFrameworkExceptionLocalizedException $e) {
                if ($this->_objectManager->get(MagentoCheckoutModelSession::class)->getUseNotice(true)) {
                    $this->messageManager->addNoticeMessage($e->getMessage());
                } else {
                    $this->messageManager->addErrorMessage($e->getMessage());
                }
                return $resultRedirect->setPath('*/*/history');
            } catch (Exception $e) {
                $this->messageManager->addExceptionMessage(
                    $e,
                    __('We can't add this item to your shopping cart right now.')
                );
                return $resultRedirect->setPath('checkout/cart');
            }
    }
        }

        $cart->save();
        return $resultRedirect->setPath('checkout/cart');
    }

I got this error Type Error occurred when creating object: MagentoSalesControllerOrderReorderInterceptor I think it’s because of MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository contruct

This is a controller for reorder – It keeps on giving me an error, I’m wondering if my code looks correct or no? is there a better a way to do this?

magento2 – Magento 2 Add Custom Image Uploader in Admin Product Edit Form

I am struggling with strange and very common issue with Custom Image Uploader in Admin. I just need to add a custom image uploader in the Product add/edit form and to save the particular image respective to that product as custom attribute. But, When i am trying to upload the file it always gives error “The file was not uploaded.”. Here is my code.

VendorModuleetcadminhtmlroutes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="Custom" frontName="Custom">
            <module name="Vendor_Module" before="Magento_Backend" />
        </route>
    </router>
</config>

VendorModuleviewadminhtmlui_componentproduct_form.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">
   <fieldset name="magenest">
       <argument name="data" xsi:type="array">
           <item name="config" xsi:type="array">
               <item name="label" xsi:type="string">Specification Image</item>
               <item name="collapsible" xsi:type="boolean">true</item>
               <item name="dataScope" xsi:type="string">data.magenest</item>
               <item name="sortOrder" xsi:type="number">10</item>
           </item>
       </argument>
<field name="specification_image">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="source" xsi:type="string">product</item>
                    <item name="label" xsi:type="string" translate="true">Specification Image</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="formElement" xsi:type="string">fileUploader</item>
                    <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
                    <item name="previewTmpl" xsi:type="string">Magento_Catalog/image-preview</item>
                    <item name="required" xsi:type="boolean">false</item>
                    <item name="sortOrder" xsi:type="number">40</item>
                    <item name="uploaderConfig" xsi:type="array">
                        <item name="url" xsi:type="url" path="Custom/product_image/upload"/>
                    </item>
                </item>
            </argument>
        </field>
   </fieldset>
</form>

VendorModuleSetupUpgradeData.php

use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupUpgradeDataInterface;
use MagentoEavSetupEavSetupFactory;
use MagentoCatalogModelProduct;
use MagentoEavModelEntityAttributeScopedAttributeInterface;


class UpgradeData implements UpgradeDataInterface
{

    /**
     * @var eavSetup
     */
    private $eavSetup;
    
    public function __construct(
        EavSetupFactory $eavSetupFactory        
    ) {
        $this->eavSetupFactory = $eavSetupFactory;        
    }

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();
        $this->eavSetup = $this->eavSetupFactory->create(('setup' => $setup));
        if (version_compare($context->getVersion(), '1.0.1') < 0) {
           
            $this->addProductImageAttribute();
        }
    }

    public function addProductImageAttribute()
    {
        $this->eavSetup->addAttribute(
            Product::ENTITY,
            'specification_image',
            (
                'type'         => 'varchar',
                'backend'      => '',
                'frontend'     => '',
                'label'        => 'Specification Image',
                'input'        => 'image',
                'global'       => ScopedAttributeInterface::SCOPE_GLOBAL,
                'visible'      => true,
                'required'     => false,
                'user_defined' => true,
                'default'      => '',
                'searchable'   => false,
                'filterable'   => false,
                'comparable'   => false,
                'unique'       => false,
                'visible_on_front' => true,
                'used_in_product_listing' => true,
                'group'        => 'General Information'
            )
        );
    }
}

VendorModuleetcdi.xml

<type name="FfcCatalogControllerAdminhtmlProductImageUpload">
    <arguments>
        <argument name="imageUploader" xsi:type="object">MagentoCatalogProductImageUpload</argument>
    </arguments>
</type>

<virtualType name="MagentoCatalogProductImageUpload" type="MagentoCatalogModelImageUploader">
    <arguments>
        <argument name="baseTmpPath" xsi:type="string">catalog/tmp/product</argument>
        <argument name="basePath" xsi:type="string">catalog/product</argument>
        <argument name="allowedExtensions" xsi:type="array">
            <item name="jpg" xsi:type="string">jpg</item>
            <item name="jpeg" xsi:type="string">jpeg</item>
            <item name="gif" xsi:type="string">gif</item>
            <item name="png" xsi:type="string">png</item>
        </argument>
        <argument name="allowedMimeTypes" xsi:type="array">
            <item name="jpg" xsi:type="string">image/jpg</item>
            <item name="jpeg" xsi:type="string">image/jpeg</item>
            <item name="gif" xsi:type="string">image/gif</item>
            <item name="png" xsi:type="string">image/png</item>
        </argument>
    </arguments>
</virtualType>    
</config>

VendorModuleControllerAdminhtmlProductImageUpload.php

<?php        

use MagentoFrameworkControllerResultFactory;
    
class Upload extends MagentoBackendAppAction
{
    
    protected $imageUploader;    
    
    private $uploaderFactory;
    
    protected $mediaDirectory;
        
    protected $storeManager;
        
    protected $coreFileStorageDatabase;
        
    protected $logger;

    protected $imageUploaders;
        
    public function __construct(
        MagentoBackendAppActionContext $context,
        MagentoCatalogModelImageUploader $imageUploader,
        MagentoMediaStorageModelFileUploaderFactory $uploaderFactory,
        MagentoFrameworkFilesystem $filesystem,
        MagentoStoreModelStoreManagerInterface $storeManager,
        MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase,
        PsrLogLoggerInterface $logger            
    ) {
        parent::__construct($context);
        $this->imageUploader = $imageUploader;
        $this->uploaderFactory = $uploaderFactory;
        $this->mediaDirectory = $filesystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
        $this->storeManager = $storeManager;
        $this->coreFileStorageDatabase = $coreFileStorageDatabase;
        $this->logger = $logger;            
    }

    
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Vendor_Module::product');
    }
        
    public function execute()
    {
        try {            
            $result = $this->imageUploader->saveFileToTmpDir('specification_image');                
            $result('cookie') = (
                'name' => $this->_getSession()->getName(),
                'value' => $this->_getSession()->getSessionId(),
                'lifetime' => $this->_getSession()->getCookieLifetime(),
                'path' => $this->_getSession()->getCookiePath(),
                'domain' => $this->_getSession()->getCookieDomain(),
            );            
        } catch (Exception $e) {
            $result = ('error' => $e->getMessage(), 'errorcode' => $e->getCode());
        }
        return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
    }
}

I didn’t find anything in the error log. I tried every possible way to find the root cause of the problem but couldn’t. I thought this problem might be due to not available of the MIME type. So i added “allowedMimeTypes” argument in di.xml but that also didn’t work out.

I followed the same way to add custom Image Uploader in Admin Category Edit Form and It’s working perfectly without any problem. But I don’t know why it’s not working with Product. Apart from solving this issue, please also guide me how to save this image with product as it’s custom attribute value in database.

I appreciate every help possible. Thank you!