magento2.3 – Magento2 Grid: Select all disabled with two dropdown filters

A client running a magento 2.3.2. store noted that he can not use the Select All when two Filters are enabled. This pertains to the Magento Grid with orders on the Sales page. The filters the client is using are Status & Storeview.

I tested this behavior and can confirm that when he uses 2 Dropdown filters, the Select All functionality gets disabled. The disabling works through adding a ‘disabled’ attribute to both the input & button element. Other combinations of filters do not seem to have this behavior. When I manually remove the attributes (devtools) the functionality seems to work properly.

My questions.

  1. Is there a good reason why the ‘Select All’ gets disabled on selecting 2 dropdown filters? The disabling seems intentional, so I figure it is not a bug?

  2. If there is no reason, I might want to adjust this behavior. Could you point me in the right direction to where this behavior is set?

I appreciate any helpful input.

magento2.3 – magento2 smtp send mail

I have a problem, i composered smtp in github and i want create send mail

I have file app/code/Mageplaza/HelloWorld/etc/email_templates.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
<template   id="helloworld_options_helloworld_group_email_template_invalid" 
            label="Email template invalid" 
            file="email/helloworld_email_template_invalid.html" 
            type="html" 
            module="Mageplaza_HelloWorld" 
            area="frontend"
/>
</config>

I have file app/code/Mageplaza/HelloWorld/view/frontend/email/helloworld_emai_template_invalid.html

<!--@subject Email Subject @-->
<!--@vars
{"store url = """:"Store Url",
"skin url="images/logo_email.gif" _area='frontend'":"Email Logo Image",
"htmlescape var=$recipient_name":"Recipient Name",
"htmlescape var=$recipient_email":"Recipient Email"}
@-->

<!--@styles
body {background: #F6F6F6; margin: 0; padding: 0;}
body, td {
color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif;
}
@-->

<body>
<div>
    <table cellspcing="0" cellpadding="0" border="0" height="100%" width="100%">
        <tr>
            <td align="center" valign="top" style="padding:20px 0 20px 0">
                <!-- (header starts here) -->
                <table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0">
                    <!-- (middle starts here) -->
                    <tr>
                        <td valign="top">
                            <h1 style="font-size:22px; font-weight: normal; line-height: 22px; margin:0 0 11px 0">Dear {{var email}},</h1>
                            This is the email that send from our magento system
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <p>Congratulation you signup complete</p>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <p>You has buy a ticket {{var name}} with type is {{var typeId}}</p>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <p>A ticket {{var typeId}} has changes about status: {{var statusId}} </p>        
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <a href="{{store url="ticket/frontend/manageaticket/"}}uniqueCode/{{var uniqueCode}}"><span>View Detail Ticket</span></a>
                            <br/>
                            view: {{store url="ticket/frontend/manageaticket/"}}uniqueCode/{{var uniqueCode}}
                        </td>
                    </tr>
                    <tr>
                        <td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align: center;">
                            <center>
                                <p style="font-size:12px; margin:0">
                                    Thank you again, <strong>{{var store.getFrontendName()}}</strong>
                                </p>
                            </center>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>
</body>

I have file app/code/Mageplaza/HelloWorld/Helper/Email.php

<?php

namespace MageplazaHelloWorldHelper;
use MagentoFrameworkAppHelperAbstractHelper;
use MagentoCustomerModelSession as CustomerSession;
use MagentoFrameworkExceptionMailException;
use MagentoFrameworkAppHelperContext;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkMessageManagerInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkUrlInterface;

class Email extends AbstractHelper {
const EMAIL_APPROVAL_INVALID = 'helloworld_options/helloworld_group/email_template_invalid';
/**
 * @var StateInterface
 */
protected $_inlineTranslation;

/**
 * @var TransportBuilder
 */
protected $_transportBuilder;

/**
 * @var CustomerSession
 */
protected $_customerSession;

/**
 * @var StoreManagerInterface
 */
protected $_storeManager;

/**
 * @var UrlInterface
 */
protected $_url;

protected $_template;

protected $_messageManager;

public function __construct(
    Context $context,
    StateInterface $inlineTranslation,
    TransportBuilder $transportBuilder,
    ManagerInterface $messageManager,
    StoreManagerInterface $storeManager,
    CustomerSession $customerSession,
    UrlInterface $url
) {
    parent::__construct($context);
    $this->_inlineTranslation = $inlineTranslation;
    $this->_transportBuilder = $transportBuilder;
    $this->_customerSession = $customerSession;
    $this->_storeManager = $storeManager;
    $this->_messageManager = $messageManager;
    $this->_url = $url;
}

protected function getConfigValue($path, $storeId) {
    return $this->scopeConfig->getValue(
        $path,
        MagentoStoreModelScopeInterface::SCOPE_STORE,
        $storeId
    );
}

protected function getTemplateId($xmlPath) {
    return $this->getConfigValue($xmlPath, $this->_storeManager->getStore()->getId());
}

protected function generateTemplate($emailTemplateVariables, $senderInfo, $receiverInfo) {
    $template = $this->_transportBuilder->setTemplateIdentifier($this->_template)
        ->setTemplateOptions(
            (
                'area' => MagentoFrameworkAppArea::AREA_FRONTEND,
                'store' => $this->_storeManager->getStore()->getId(),
            )
        )
        ->setTemplateVars($emailTemplateVariables)
        ->setFrom($senderInfo)
        ->addTo($receiverInfo('email'), $receiverInfo('name'))
        ->setReplyTo($senderInfo('email'), $senderInfo('name'));

    return $this;
}

public function sendEmail($template, $emailTemplateVariables){
    $result = (
        'error' => false
    );
    $this->_template = $this->getTemplateId($template);

    $this->_inlineTranslation->suspend();

    $senderInfo = (
        'email' => $this->getConfigValue( 'trans_email/ident_custom2/email', $this->_storeManager->getStore()->getId()),
        'name' => $this->getConfigValue( 'trans_email/ident_general/name', $this->_storeManager->getStore()->getId())
    );

    $receiverInfo = (
        'email' => $emailTemplateVariables('email'),
        'name' => $emailTemplateVariables('name')
    );

    $this->generateTemplate($emailTemplateVariables, $senderInfo, $receiverInfo);

    try {
        $transport = $this->_transportBuilder->getTransport();
        $transport->sendMessage();
        $result = (
            'error' => false,
            'message' => 'Email is sent successfully'
        );
    } catch (Exception $e) {
        $result = (
            'error' => true,
            'message' => $e->getMessage()
        );
    }

    $this->_inlineTranslation->resume();

    return $result;
}

public function sendEmailHelloWorldInvalid($emailTempVariables) {
    $this->sendEmail(self::EMAIL_APPROVAL_INVALID, $emailTempVariables);
}
}

And i have file app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post/SendMail.php

<?php

namespace MageplazaHelloWorldControllerAdminhtmlPost;

use MagentoFrameworkEventObserverInterface;
use MageplazaHelloWorldHelperEmail;

class SendMail implements ObserverInterface

{
private $helperEmail;

public function __construct(
    Email $helperEmail
) {
    $this->helperEmail = $helperEmail;
}
public function execute(MagentoFrameworkEventObserver $observer)
{
    $data('name') = 'Boll';
    $data('email') = 'abc@gmail.com';

    return $this->helperEmail->sendEmailHelloWorldInvalid($data);
}
}

I don’t know which file I am missing. Help me please!

magento2.3 – Magento 2.3 – Product images in order history

I want to load max 3 product images in the order history page on customer account.

I currently have a perfectly working code using $objectManager. But because Magento does not recommend to use objectManager, I want to transform this into a module.

How can I transform this code into a module?

Code:

<?php $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $_product = $objectManager->get('MagentoCatalogModelProduct')->load($itm->getProductId());
            $imageHelper  = $objectManager->get('MagentoCatalogHelperImage');
            $image_url = $imageHelper->init($_product, 'product_page_image_small')->setImageFile($_product->getImage())->resize(160, 160)->getUrl();?>

magento2.3 – Magento 2.3 – Get category of item related foreach

Create a module and override catalog_product_view.xml in your module. then create one block to set your business logic to the template.

Vendor/Module/view/frontend/layout/catalog_product_view.xml

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="product.info.main">
            <container name="productdetailcat"  htmlTag="div" htmlClass="productdetailcat"  after="product.info.price">
                <block class="VendorModuleBlockCustom" name="catnameurl" template="Vendor_Module::custom_cat.phtml" />
            </container>
        </referenceContainer>
    </body>
</page>

Vendor/Module/Block/Custom.php

<?php 

namespace VendorModuleBlock;

use MagentoFrameworkViewElementTemplate;
use MagentoFrameworkViewElementTemplateContext;
use MagentoFrameworkViewPageConfig;
use MagentoFrameworkRegistry;
use MagentoCatalogModelCategoryFactory;
use MagentoCatalogModelCategory;

class Custom extends Template
{
    private $_registry;
    private $_categoryFactory;
    protected $_category;

    public function __construct(
        Context $context,
        Config $pageConfig,
        Registry $registry,
        Category $catgory,
        CategoryFactory $categoryfactory,
        array $data = ()
    ) {
        parent::__construct($context, $data);
        $this->pageConfig = $pageConfig;
        $this->_registry = $registry;
        $this->_categoryFactory = $categoryfactory;
        $this->_category = $catgory;
    }

    public function getCategoryCollection() 
    {
        $ProductID = $this->_registry->registry('current_product');

        $categories = $ProductID->getCategoryIds();
        foreach($categories as $category)
        {
          $cat = $this->_categoryFactory->create()->load($category);
          $caturl = $cat->getUrl();
          $catName = $cat->getName();
         }

        return $catName;
    }
}

?>

Vendor/Module/view/frontend/templates/custom_cat.phtml

<?php 

$CatName = $block->getCategoryCollection();

echo '<PRE>';
print_r($CatName);

?>

Here is display last category name because in foreach return the last name. as per your logic custom in our code and display all cat names and URLs. If You have any query please let me know.

I hope this will help you….!

magento2.3 – Layout switcher for product view magento 2.3.5 (Custom layout update)

Since the update to Magento 2.3.x it is possible to change the layout of the product output using a product id or sku:

Unfortunately there is no possibility to give different designs generally for product types with custom layout update like:

catalog_product_view_selectable_<to-all-products>_<layout-name>.xml

Is there any other way to control the design of the product output in admin?

As an example I would need for the bundle product three different layouts in the frontend, which layout should be loaded controllable via admin in the product itself.

magento2.3 – Magento 2 can’t remove post params when reload

I’m trying to import stock using csv. When I click on submit, the import functionality works fine. But when i click on reload when it is posting then it loads until the post function completes.

<?php
if(isset($_POST('submit'))){
    if (!file_exists($mediaPath.'csv')) {
        mkdir($mediaPath.'csv', 0777, true);
    }
    $file_type = $_FILES('file')('type'); //returns the mimetype
    $allowed = array('text/csv');
    if(!in_array($file_type, $allowed)) {?>
    <h1 class="error">Only CSV files allowed</h1>
    <tr>
        <td>Wrong format</td>
        <td>Wrong format</td>
        <td>Wrong format</td>
    </tr>
    <?php
   $model->addData((
    "title" => 'Title 01',
    "content" => 'Content 01',
    "summary" => "true",
    "create_at" => new Zend_Db_Expr('NOW()')
    ));
    $saveData = $model->save();

    }else{    
    $displayFlag = 1;
    $csv =  $_FILES('file');    
    $targetdir = $mediaPath;   
    $image_name=$_FILES('file')('name');
    $temp = explode(".", $image_name);
    $newfilename = round(microtime(true)) . '.' . end($temp);
    $imagepath=$mediaPath."csv/".$image_name;
    if(move_uploaded_file($_FILES("file")("tmp_name"),$imagepath)){
        $csvFile = file($imagepath);
        $data = ();
        foreach ($csvFile as $line) {
            $data() = str_getcsv($line, ",", '"');
        }
        $keys = ();
        $result = ();
        foreach($data as $key => $value){
            if($key == 0){
                $keys = $value;
            }            
        }
        foreach($data as $key => $value){
            if($key !== 0){
                $result() = array_combine($keys, $value);
            }            
        }
        foreach($result as $key => $value){
            if(isset($value('sku'))){
                if($product->getIdBySku($value('sku'))) {
                    $stockItem = $stockRegistry->getStockItemBySku($value('sku'));
                    $stockItem->setQty($value('qty'));
                    $sku = $value('sku');            
                    if($stockRegistry->updateStockItemBySku($sku, $stockItem)){                
                        ?>
                        <tr>
                            <td><?php echo $value('sku') ?></td>
                            <td><?php echo $value('qty') ?></td>
                            <td>Updated</td>
                        </tr>
                    <?php
                    }else{?>
                        <tr>
                            <td><?php echo $value('sku') ?></td>
                            <td><?php echo $value('qty') ?></td>
                            <td>Updated</td>
                        </tr>
                        <?php
                    }
                }else{ ?>
                     <tr>
                            <td><?php echo $value('sku') ?></td>
                            <td><?php echo $value('qty') ?></td>
                            <td>Sku Not found</td>
                        </tr>
                <?php
                }
            }else{
                ?>
                 <h1 class="error">Only CSV files allowed</h1>
                    <tr>
                        <td>Wrong format</td>
                        <td>Wrong format</td>
                        <td>Wrong format</td>
                    </tr>
            <?php 
                break;
            }            
        }
    }
}
header('Location: http://192.168.31.236/magento/admin/grid/grid/index');
exit();
}
?>
</table>

I can’t load any admin pages until this post function completed.

magento2.3 – What is the most popular database choice for Magento 2?

this question sounds more like a poll because I’m just curious as to what database is the most commonly used for Magento2. I currently use MariaDB 10 from following an installation tutorial online, but I’m a bit wary because I’ve recently read the official documentation and it says that MariaDB may not be fully compatible with Magento2. What is the most widely used database for Magento2?

magento2.3 – Add div background image in email template

I have created a custom email template and I want to add background image to one of its div element. I have added html file in my email with below content.

<div
  class="container"
  width="100%"
  style="
    background-image: url('{{view url="My_Module/img/myimage.png"}}');
    padding: 20px 60px;
    background-size: cover;
  "
>

But its not working. It removes whole style tag from my div in final email.
If I am using complete image static url, it works correctly like below.

<div
  class="container"
  width="100%"
  style="
    background-image: url('https://domain.com/my-full-image-path/myimage.png');
    padding: 20px 60px;
    background-size: cover;
  "
>

Please note here that I want to add background image and not img field with src. I have checked and found that the image path is correct so no issues with image path here.
Does anyone know how we can add background image in email template content.

magento2.3 – Magento 2.3 extend product list collection in child template – error on search

We use the following method to extend the product list collection inside a child template.
This works fine for the product catalog list page, but gives a error (skips the load from the element) on the search page. The setProduct element does not work on search.

How can we solve this to make this also work on the search page?

Code:

<?php
namespace VendorCatalogProductBlockProduct;

class Data extends MagentoFrameworkViewElementTemplate
{
    private $product;

    public function setProduct($product)
    {
        $this->product = $product;
    }

    public function getProduct()
    {
      return $this->product;  
    }

}

Inside list.phtml;

<ul class="product-highlights-specs">
   <?php $block->getChildBlock("product-specs")->setProduct($_product);
   echo $block->getChildHtml('product-specs', false);?>
</ul>

Inside product-specs template;

<?php
$_product = $block->getProduct();
$attributeset = $_product->getAttributeSetId();

echo $_product->getName();?>
?>