magento2 – Restrict shipping method based on product attribute

I’m trying to restrict a shipping method in afterCollectRates based on a custom product attribute (which I’m injecting with the help of catalog_attributes.xml

public function afterCollectRates(Tablerate $tablerate, $result)
{
    $items = $this->checkoutSession->getQuote()->getAllVisibleItems();
    foreach ($items as $item) {
        if ($item->getProduct()->getMyAttribute()) {
            return false;
        }
    }
    return $result;
}

This hides the shipping method if there’s a product with the attribute in cart. However, I need the exact opposite. I need to hide the shipping method if no product in cart does have the attribute.

Obviously the cart can have products with and without the attribute, so I can not simply do !$item->getProduct()->getBulkgood() since the function only accepts return: false;

Any way to make this work?

magento2 – Ajax is not working going to 404 in Magento 2.4.2 Admin

I am creating module for frontend and backend and want to run ajax with in the modules.
My ajax is perfectly working on frontend but it doesn’t work on admin side.

My Ajax URL is http://127.0.0.1/mag/createmenubackend/create/ajax/?isAjax=true which goes to 404.

My Controller file path ( app/code/Hl/CreateMenuBackend/Controller/Adminhtml/Create/Ajax.php )

    namespace HlCreateMenuBackendControllerAdminhtmlCreate;

    class Ajax extends MagentoBackendAppAction
    {
            protected $resultPageFactory = false;      
            public function __construct(
                    MagentoBackendAppActionContext $context,
                    MagentoFrameworkViewResultPageFactory $resultPageFactory
            ) {
                    parent::__construct($context);
                    $this->resultPageFactory = $resultPageFactory;
            } 
            public function execute()
            {       
                    die('aaaa');
            }
    }

My routes.xml file ( app/code/Hl/CreateMenuBackend/etc/adminhtml/routes.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="createmenubackend" frontName="createmenubackend">
<module name="Hl_CreateMenuBackend"/>
</route>
</router>
</config>

My JS File is ( Hl/CreateMenuBackend/view/adminhtml/web/js/adminscript.js )

    require((
    'jquery',
    'mage/url'
), function($,url){
    'use strict';
    url.setBaseUrl(BASE_URL);
    var linkUrl = url.build('createmenubackend/create/ajax');
    console.log('hl_home_page_div');
    $( ".hl_home_page_div" ).on( 'click', '.hl_home_page_data',function() {
        console.log('hl_home_page_div 222222222');
        $.ajax({
            url: 'http://hl.local/createmenubackend/create/ajax/'+'?isAjax=true',
            data: {form_key: window.FORM_KEY, 'value':'c'},
            type: "POST",
            dataType : 'json',
            success: function(result){
             
                alert(result);
            }
        });        
    });
});

The result but AJAX goes to 404 Not Found. What’s the issue i didn’t get this.Any Help is appreciated.

magento2 – what is the purpose of eav_entity_attribute table

Well, Magento is storing some model’s data (ex. products, categories, customers) with EAV standard.

EAV means Entity, Attribute, (Attribute) Value, which means that data is stored inside database vertically.

For example product:

Product Type Entity is delegated inside eav_entity_type table with code product.

Product Entities are stored inside catalog_product_entity table.

Attributes definitions are stored inside eav_attribute table (regardless of entity type).

Attribute Values are stored inside catalog_product_entity_TYPE tables.

eav_entity_attribute stores links of attributes with entity types, attribute sets, attribute groups and saves sorting for them.

magento2 – Multiselect Attribute created through module can’t be set programatically

I am on a Magento 2.1 installation using a Venus Theme Module called Brands 2.0.

The module creates a product_brand multi select attribute with the following code:

$eavSetup = $this->eavSetupFactory->create(('setup' => $setup));
        $data = array(
            'group' => 'General',
            'type' => 'varchar',
            'input' => 'multiselect',
            'default' => 1,
            'label' => 'Product Brand',
            'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
            'frontend' => '',
            'source' => 'VesBrandModelBrandlist',
            'visible' => 1,
            'required' => 1,
            'user_defined' => 1,
            'used_for_price_rules' => 1,
            'position' => 2,
            'unique' => 0,
            'default' => '',
            'sort_order' => 100,
            'is_global' => MagentoCatalogModelResourceModelEavAttribute::SCOPE_STORE,
            'is_required' => 0,
            'is_configurable' => 1,
            'is_searchable' => 0,
            'is_visible_in_advanced_search' => 0,
            'is_comparable' => 0,
            'is_filterable' => 0,
            'is_filterable_in_search' => 1,
            'is_used_for_promo_rules' => 1,
            'is_html_allowed_on_front' => 0,
            'is_visible_on_front' => 1,
            'used_in_product_listing' => 1,
            'used_for_sort_by' => 0,
            );
        $eavSetup->addAttribute(
            MagentoCatalogModelProduct::ENTITY,
            'product_brand',
            $data);

Now we are trying to add products through an API, and everything is working fine except for setting this product_brand attribute. When using:

$product->setData('product_brand', $authCSV);

where $authCSV is a CSV list of option IDs. This works for other multi selects but not for product_brand. No errors are thrown but the attribute does not get saved along with the rest of them.

Any help would be appreciated.

magento2 – Magento 2 how to assign a custom order status when canceling an order with a specific payment method

You can use event order_cancel_after and change status this way:

$order = $observer->getEvent()->getData('order');
$order->setStatus('your_custom_status_code');

Then order will be saved by the OrderService in the cancel method:

public function cancel($id)
{
    $order = $this->orderRepository->get($id);
    if ($order->canCancel()) {
        $order->cancel(); // <<< Inside this method the event fired
        $this->orderRepository->save($order); // Magento saves order with new custom status
        return true;
    }

    return false;
}

The payment method you can check inside observer using $order->getPaymentMethod(), it will return string (code).

magento2 – Magento 2: Adding a Javascript library

I am trying to add an animation library called Sal, built on pure Javascript (Does not rely on jQuery). Maybe I am missing something, but I followed the instructions on adding via require-config, and I am getting a sal is not defined error.

I have also tried just adding the js file via default_head_blocks.xml

My require-config.js

var config = {
    paths: {
        'sal': 'js/sal'
    },
    deps: (
        "js/script",
        "js/main"
    )
};

My main.js

define(('sal'), function(){
  "use strict";
  sal();
  console.log(" ====== main.js is loaded====== ");
});

magento2 – send email to client – custom module

Guys after a lot of research, I managed to create a module that sends an email to the store owner, but I also need him to send an email with the content to the customer. Does anyone know how I can change my controller so that it sends the content to the client as well?

<?php

namespace vendormoduleControllerIndex;

use ZendLogFilterTimestamp;
use MagentoStoreModelStoreManagerInterface;

class Post extends MagentoFrameworkAppActionAction
{
    const XML_PATH_EMAIL_RECIPIENT_NAME = 'trans_email/ident_support/name';
    const XML_PATH_EMAIL_RECIPIENT_EMAIL = 'trans_email/ident_support/email';


    protected $_inlineTranslation;
    protected $_transportBuilder;
    protected $_scopeConfig;
    protected $_logLoggerInterface;
    protected $storeManager;

    public function __construct(
        MagentoFrameworkAppActionContext $context,
        MagentoFrameworkTranslateInlineStateInterface $inlineTranslation,
        MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        PsrLogLoggerInterface $loggerInterface,
        StoreManagerInterface $storeManager,
        array $data = ()

    ) {
        $this->_inlineTranslation = $inlineTranslation;
        $this->_transportBuilder = $transportBuilder;
        $this->_scopeConfig = $scopeConfig;
        $this->_logLoggerInterface = $loggerInterface;
        $this->messageManager = $context->getMessageManager();
        $this->storeManager = $storeManager;

        parent::__construct($context);
    }

    public function execute()
    {
        $post = $this->getRequest()->getPost();
        try {
            // Send Mail
            $this->_inlineTranslation->suspend();

            $senderName = $post('name');
            $senderEmail = $post('email');

            $sender = (
                'name' => $senderName,
                'email' => $senderEmail
            );

            $sentToEmail = $this->_scopeConfig->getValue('trans_email/ident_general/email', MagentoStoreModelScopeInterface::SCOPE_STORE);

            $sentToName = $this->_scopeConfig->getValue('trans_email/ident_general/name', MagentoStoreModelScopeInterface::SCOPE_STORE);




            $transport = $this->_transportBuilder
                ->setTemplateIdentifier('customemail_email_template')
                ->setTemplateOptions(
                    (
                        'area' => 'frontend',
                        'store' => $this->storeManager->getStore()->getId()
                    )
                )
                ->setTemplateVars((
                    'name'  => $post('name'),
                    'email'  => $post('email')
                ))
                ->setFromByScope($sender)
                ->addTo($sentToEmail, $sentToName)
                //->addTo('test@test.com', 'owner')
                ->getTransport();

            $transport->sendMessage();

            $this->_inlineTranslation->resume();
            $this->messageManager->addSuccess('sucess!');
            $this->_redirect('customemail/index/index');
        } catch (Exception $e) {
            $this->messageManager->addError($e->getMessage());
            $this->_logLoggerInterface->debug($e->getMessage());
            exit;
        }
    }
}

magento2 – Magento 2: Not able to send email

magento2 – Magento 2: Not able to send email – Magento Stack Exchange

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123