#StackBounty: #magento2 #module #layout #plugin #app Get Selected country id and region name in class LayoutProcessor of cusom module

Bounty: 50

I have a custom module app/code/Learning/FirstUnit/ and in that i have LayoutProcessor.php file in app/code/Learning/FirstUnit/Plugin.

Please see the below code in LayoutProcessor.php

<?php

namespace LearningFirstUnitPlugin;

use MagentoDirectoryHelperData as DirectoryHelper;
use MagentoDirectoryModelResourceModelCountryCollectionFactory;
use MagentoStoreModelStoreManagerInterface;
use function PHPUnitFrameworkassertIsCallable;

class LayoutProcessor
{

    public function afterProcess(
        MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
        $result
    ) {
  
        //For shipping form
        $result['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children']['city'] = [
            'component' => 'Magento_Ui/js/form/element/select',
            'config' => [
                'customScope' => 'shippingAddress',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/select',
                'id' => 'drop-down',
            ],
            'dataScope' => 'shippingAddress.city',
            'label' => __('City'),
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' => [],
            'sortOrder' => 70,
            'id' => 'drop-down',
            'options' => $this->getCitiesDropdown()
        ];

        //For Billing Form
        foreach ($result['components']['checkout']['children']['steps']['children']['billing-step']['children']
                 ['payment']['children']['payments-list']['children'] as $key => $payment) {
            if (isset($payment['children']['form-fields']['children']['city'])) {
                $result['components']['checkout']['children']['steps']['children']['billing-step']['children']
                ['payment']['children']['payments-list']['children'][$key]['children']['form-fields']['children']
                ['city'] = [
                    'component' => 'Magento_Ui/js/form/element/select',
                    'config' => [
                        'customScope' => 'shippingAddress',
                        'template' => 'ui/form/field',
                        'elementTmpl' => 'ui/form/element/select',
                        'id' => 'drop-down',
                    ],
                    'label' => __('City'),
                    'provider' => 'checkoutProvider',
                    'visible' => true,
                    'validation' => [],
                    'sortOrder' => 70,
                    'id' => 'drop-down',
                    'options' => $this->getCitiesDropdown()
                ];
            }
        }

        return $result;

    }

    public function getCitiesDropdown()
    {
        
        return [
        ['value' => "test1", "label" => "Test city 1", "is_default" => true], 
        ['value' => "test2", "label" => "Test city 2", "is_default" => false],
        ['value' => "test3", "label" => "Test city 3", "is_default" => false]
        ];
    }

}

This code is for to make the city field in checkout page as dropdown.

In getCitiesDropdown function I need to get the id of user selected country and region name that user type or selected . How can I get this .

I have custom table in database, so if I get the user typed region name then I will load the corresponding city name in the dropdown form that table.

Please help.


Get this bounty!!!

#StackBounty: #magento2 #module #sales-order-grid Get additional_information from sales_order_payment to show in backend sales order grid

Bounty: 50

I have a custom sales order grid module I want to extend, to show the information from the field additional_information, in the table sales_order_payment.

I have this right now, but it ain’t showing the payment method like Invoice or Credit Card, only the payment provider.

Path:

appcodeVendorSalesOrderGridviewadminhtmlui_componentsales_order_grid.xml

Code:

    <column name="payment_method" component="Magento_Ui/js/grid/columns/select">
        <settings>
            <filter>select</filter>
            <options class="MagentoPaymentUiComponentListingColumnMethodOptions"/>
            <dataType>select</dataType>
            <label translate="true">Payment Method</label>
            <visible>false</visible>
        </settings>
    </column>

The data in additional_information is stored like this:

{"svea_order_id":0000000,"country_id":"SE","method_title":"Svea 
Checkout","svea_payment_method":"INVOICE","svea_queue_id":"0000000"}

or

{"svea_order_id":0000000,"country_id":"SE","method_title":"Svea 
Checkout","svea_payment_method":"SVEACARDPAY_PF","svea_delivery_id":0000000}

And I want to fetch the data INVOICE and SVEACARDPAY_PF and others to show in the sales order grid.

Thank you,


Get this bounty!!!

#StackBounty: #module #sales-order Magento 2: Create Order Programmatically without products in stock

Bounty: 50

Below is code to create order Programatically , it is working fine , i want order to be created even when products is out of stock or less quantity

  public function createMageOrder($orderData) {
        $store=$this->_storeManager->getStore();
        $websiteId = $this->_storeManager->getStore()->getWebsiteId();
        $customer=$this->customerFactory->create();
        $customer->setWebsiteId($websiteId);
        $customer->loadByEmail($orderData['email']);// load customet by email address
        263135
        if(!$customer->getEntityId()){
            //If not avilable then create this customer 
            $customer->setWebsiteId($websiteId)
                    ->setStore($store)
                    ->setFirstname($orderData['shipping_address']['firstname'])
                    ->setLastname($orderData['shipping_address']['lastname'])
                    ->setEmail($orderData['email']) 
                    ->setPassword($orderData['email']);
            $customer->save();
        }
        $quote=$this->quote->create(); //Create object of quote
        $quote->setStore($store); //set store for which you create quote
        // if you have allready buyer id then you can load customer directly 
        $customer= $this->customerRepository->getById($customer->getEntityId());
        $quote->setCurrency();
        $quote->assignCustomer($customer); //Assign quote to customer
 
        //add items in quote
        foreach($orderData['items'] as $item){
            $product=$this->_product->load($item['product_id']);
            $product->setPrice($item['price']);
            $quote->addProduct(
                $product,
                intval($item['qty'])
            );
        }
 
        //Set Address to quote
        $quote->getBillingAddress()->addData($orderData['shipping_address']);
        $quote->getShippingAddress()->addData($orderData['shipping_address']);
 
        // Collect Rates and Set Shipping & Payment Method
 
        $shippingAddress=$quote->getShippingAddress();
        $shippingAddress->setCollectShippingRates(true)
                        ->collectShippingRates()
                        ->setShippingMethod('freeshipping_freeshipping'); //shipping method
        $quote->setPaymentMethod('checkmo'); //payment method
        $quote->setInventoryProcessed(false); //not effetc inventory
        $quote->save(); //Now Save quote and your quote is ready
 
        // Set Sales Order Payment
        $quote->getPayment()->importData(['method' => 'checkmo']);
 
        // Collect Totals & Save Quote
        $quote->collectTotals()->save();
 
        // Create Order From Quote
        $order = $this->quoteManagement->submit($quote);
        
        $order->setEmailSent(0);
        $increment_id = $order->getRealOrderId();
        if($order->getEntityId()){
            $result['order_id']= $order->getRealOrderId();
        }else{
            $result=['error'=>1,'msg'=>'Your custom message'];
        }
        return $result;
    }
}
 


Get this bounty!!!

#StackBounty: #module #event-observer #magento2.4 #plugin #stock Magento 2.4.1 Move Out of Stock In last Of Category Listing

Bounty: 100

I want to move out of stock product in last of the category listing, itried below code but same seems not working.

app/code/Meetanshi/StockQuantity/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
   <module name="Meetanshi_StockQuantity" setup_version="1.0.0"/>
</config>

app/code/Meetanshi/StockQuantity/etc/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
   <event name="catalog_block_product_list_collection">
       <observer name="stockLast" instance="MeetanshiStockQuantityObserverStockLast" />
   </event>
</config>

app/code/Meetanshi/StockQuantity/Observer/StockLast.php

<?php
namespace MeetanshiStockQuantityObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppConfigScopeConfigInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkEventObserver;
use MagentoCatalogBlockProductProductListToolbar as CoreToolbar;
class StockLast implements ObserverInterface
{
   protected $scopeConfig;
   protected $_storeManager;
   protected $coreToolbar;
   public function __construct(
       ScopeConfigInterface $scopeConfig,
       StoreManagerInterface $storeManager,
       CoreToolbar $toolbar
   )
   {
       $this->scopeConfig = $scopeConfig;
       $this->_storeManager = $storeManager;
       $this->coreToolbar = $toolbar;
   }
   public function execute(Observer $observer)
   {
       $collection = $observer->getEvent()->getData('collection');
       try {
           $websiteId = 0;
           $stockId = 'stock_id';
           $collection->getSelect()->joinLeft(
               array('_inv' => $collection->getResource()->getTable('cataloginventory_stock_status')),
               "_inv.product_id = e.entity_id and _inv.website_id=$websiteId",
               array('stock_status')
           );
           $collection->addExpressionAttributeToSelect('in_stock', 'IFNULL(_inv.stock_status,0)', array());
           $collection->getSelect()->reset('order');
           $collection->getSelect()->order('in_stock DESC');
           //code for Filter Price Low to High or High to Low with stock filter.
           if ($this->coreToolbar->getCurrentOrder() == 'price') {
               $direction = $this->coreToolbar->getCurrentDirection();
               $collection->getSelect()->order("min_price $direction");
           }
       } catch (Exception $e) {
       }
       return $this;
   }
}


Get this bounty!!!

#StackBounty: #magento2 #module #adminhtml #overrides #product-images Magento 2 how to override theme-adminhtml-backend view.xml in cus…

Bounty: 50

By default Magento 2 creates more than 20 duplicates of each product image..! (why???)

I have got this down to 5 using view.xml in my theme, but there is one extra set of image sizes I need to change, these are set in ‘/vendor/magento/theme-adminhtml-backend/etc/view.xml‘. They are: product_listing_thumbnail, product_listing_thumbnail_preview, product_thumbnail_image.

I want to update it using my custom module. I have it at this path ‘app/code/Vendor/Module/view/adminhtml/etc/view.xml‘. But this is wrong. Is there a correct path that will work? (If creating an admin theme is the only way then I guess I could do that, but seems overkill for just one small change).

(Have spent ages looking online and through docs but can only find info for frontend view.xml, which I am already using, and putting the image names in this file does not work).

Many Thanks!


Get this bounty!!!

#StackBounty: #magento2 #module #magento2.3.4 #carrier #magento-shipping how to control the sort order of shipping method's rates i…

Bounty: 50

I’m trying to build a custom carrier class (shipping method) that display shipping methods based on time/date related third party API , I tried to find out a solution to sort the below options but I failed

has any one faced such an issue ? how do magento sort these options ?

any help is really appreciated
thanks

Shipping carrier - custom class - time related shipping


Get this bounty!!!

#StackBounty: #magento2 #module #magento2.3.4 #carrier #magento-shipping how to control the sort order of shipping method's rates i…

Bounty: 50

I’m trying to build a custom carrier class (shipping method) that display shipping methods based on time/date related third party API , I tried to find out a solution to sort the below options but I failed

has any one faced such an issue ? how do magento sort these options ?

any help is really appreciated
thanks

Shipping carrier - custom class - time related shipping


Get this bounty!!!

#StackBounty: #magento2 #module #magento2.3.4 #carrier #magento-shipping how to control the sort order of shipping method's rates i…

Bounty: 50

I’m trying to build a custom carrier class (shipping method) that display shipping methods based on time/date related third party API , I tried to find out a solution to sort the below options but I failed

has any one faced such an issue ? how do magento sort these options ?

any help is really appreciated
thanks

Shipping carrier - custom class - time related shipping


Get this bounty!!!

#StackBounty: #magento2 #module #magento2.3.4 #carrier #magento-shipping how to control the sort order of shipping method's rates i…

Bounty: 50

I’m trying to build a custom carrier class (shipping method) that display shipping methods based on time/date related third party API , I tried to find out a solution to sort the below options but I failed

has any one faced such an issue ? how do magento sort these options ?

any help is really appreciated
thanks

Shipping carrier - custom class - time related shipping


Get this bounty!!!