magento2 – Magento 2 – Pass data to checkout during runtime

I created a new carrier method for express shipping. I need to show a dynamic message which I am generating based on the products in the cart. There are some product categories which are not allowed with the new carrier method.

So I need to show a message like:

The following products are not compatible with the express shipping
method:

I am generating the message in the code where I am creating the carrier. But I don’t know how to pass the generated message to the view.

app/code/Company/Shipping/Model/Carrier/CompanyExpress.php

<?php
namespace CompanyShippingModelCarrier;

use MagentoQuoteModelQuoteAddressRateRequest;
use MagentoShippingModelRateResult;

class CompanyExpress extends MagentoShippingModelCarrierAbstractCarrier
              implements MagentoShippingModelCarrierCarrierInterface
{
    ...
    
    public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }

        /** @var MagentoShippingModelRateResult $result */
        $result = $this->_rateResultFactory->create();

        /** @var MagentoCatalogModelCategory $categoryModel */
        $categoryModel = $this->_categoryFactory->create();

        /** @var MagentoCheckoutModelCart $cart */
        $cart = $this->_cartFactory->create();

        /** @var MagentoQuoteModelQuote $quote */
        $quote = $cart->getQuote();

        $rule = $this->_carrierHelper->getShippingRule(
                     $quote
                    ,$this->_productRepository
                    ,$categoryModel
                    ,$this->_scopeConfig
                );
        if ( ! $rule) { return false; }

    // Add Express Shipping Method
        $expressRule = $rule("rules")("express");

        if ($expressRule("active")) {

            /** @var MagentoQuoteModelQuoteAddressRateResultMethod $method */
            $method = $this->_rateMethodFactory->create();

            $carrierTitle = $expressRule("carrierTitle");
            $methodTitle = $expressRule("methodTitle");
            $shippingCost = $expressRule("shippingCost");

// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

            $note = $this->_generateNote($expressRule);     // <----- How can I pass this note to the view?

// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

            $method->setCarrier($this->_code);
            $method->setMethod($this->_code);
            $method->setMethodTitle($methodTitle);
            $method->setCarrierTitle($carrierTitle);
            $method->setPrice($shippingCost);
            $method->setCost($shippingCost);

            $result->append($method);
        }

        return $result;
    }
    
    private function _generateNote($expressRule)
    {
        $block = $this->_notAllowedCategoriesBlockFactory->create();            
        $block->setExpressRule($expressRule);
        $html = str_replace(PHP_EOL, '', $block->toHtml());

        return $html;
    }
    
    ...

As you can see I am generating the Note with _generateNote() but I don’t know how I can pass it to the view.

Any help is appreciated.

how to allow user select shipping location(a custom locations dropdown) in checkout and recalculate values woocommerce

i need to know 2 things

  1. how do i add custom shipping zones to a determinate contry (I need to add some neightbours of a main city)
  2. How do i allow users to select the shipping zone when chekout or in the cart, and recalculate the total

php – MercadoPago Checkout Pro: Como armazenar retorno de status de pagamento usando a API

Estou desenvolvendo uma aplicação que utilizará o Checkout Pro do MercadoPago. Sou leigo nessa área e gostaria de armazenar os status de compra do cliente dentro de uma tabela no MySql. No caso para tentar resolver essa dúvida, estou vendo um artigo do MercadoPago sobre IPN (Instant Payment Notification) porém não estou conseguindo achar um caminho correto para armazenar estas notificações.

A princípio já possuo uma tabela chamada pedidos e dentro dessa tabela criei uma coluna status. Abaixo segue um exemplo da estrutura da mesma:

pedidoID | cliente     | preco  | status
-------------------------------------------
0001     |João José    | 25.00  | Aprovado
0002     |Maria Joana  | 20.00  | Pendente
0003     |Maria Andrade| 30.00  | Cancelado

entretanto, a minha dúvida é como receber este retorno (status) do processo de pagamento do cliente no checkout Pro para que eu possa inserir essa informação conforme no exemplo da tabela acima na coluna status? No artigo citado, o mesmo diz que tenho que criar uma URL conforme abaixo:

www.yoursite.com/notifications

onde no caso criei um arquivo php chamado notifications porém não sei ao certo se seria isso que eu deveria fazer. Abaixo uma explicação a respeito, dentro do artigo de suporte do MercadoPago Checkout Pro:

(Exemplo: Se configurar a URL: www.yoursite.com/notifications, você receberá as notificações de pagamento desta maneira: www.yoursite.com/notifications?topic=payment&id=123456789)

Abaixo, um código em php fornecido pelo artigo de ajuda, onde informa o seguinte:

Implemente o receptor de notificações usando o seguinte código como exemplo:

<?php
    MercadoPagoSDK::setAccessToken("ENV_ACCESS_TOKEN");

    $merchant_order = null;

    switch($_GET("topic")) {
        case "payment":
            $payment = MercadoPagoPayment::find_by_id($_GET("id"));
            // Get the payment and the corresponding merchant_order reported by the IPN.
            $merchant_order = MercadoPagoMerchantOrder::find_by_id($payment->order->id);
            break;
        case "merchant_order":
            $merchant_order = MercadoPagoMerchantOrder::find_by_id($_GET("id"));
            break;
    }

    $paid_amount = 0;
    foreach ($merchant_order->payments as $payment) {   
        if ($payment('status') == 'approved'){
            $paid_amount += $payment('transaction_amount');
        }
    }

    // If the payment's transaction amount is equal (or bigger) than the merchant_order's amount you can release your items
    if($paid_amount >= $merchant_order->total_amount){
        if (count($merchant_order->shipments)>0) { // The merchant_order has shipments
            if($merchant_order->shipments(0)->status == "ready_to_ship") {
                print_r("Totally paid. Print the label and release your item.");
            }
        } else { // The merchant_order don't has any shipments
            print_r("Totally paid. Release your item.");
        }
    } else {
        print_r("Not paid yet. Do not release your item.");
    }

?>

No mais, eu já possuo as credenciais de produção e testes e a dúvida mesmo é saber qual caminho certo eu devo tomar para poder implantar essa informação em minha aplicação? Desde já agradeço a atenção.

checkout – Magento2 Disable Shipping Method Selection Only in Shipping Method page

I want to ask customers to select their own shipping method rather than selecting one shipping method by default. here i tried the following code in app/design/frontend/Mypackahe/mytheme/Magento_Checkout/web/js/model/checkout-data-resolver.js

In this file i changed from

selectShippingMethodAction(ratesData(0));

to

selectShippingMethodAction(null);

It works perfectly but the problem is in cart page it is showing 0 as order cart total. When ever user opened view/edit cart page then it is showing 0 order total why because no shipping method selected on estimate shipping method.

I want to show order total on cart page & also i want to deselect default option of shipping methods so user must select any of them. Any idea on what i am wrong here?

magento2 – Magento 2 “Place order” button not working with stripe and One Step Checkout Amasty

I’ve integrated Stripe (its official module, latest version 2.1.4) as payment method along One Step Checkout from Amasty in Magento 2.3.5.

Something seems wrong as “Place order” button is not working. “Place order” button is clickable, but nothing happens. When I select another payment method, it works fine. But selecting “Stripe” as payment method it don’t.

If I disable One Step Checkout, it also works fine (including Stripe).

So the problem is between Stripe module and One Step Checkout from Amasty. Any thoughts on this?

magento2 – Magento 2.3.4 Region Missing When Creating a New Address During Checkout

Running into an issue during checkout on the Shipping step. When you add a new address to ship to during this step, it asks you for your City, State, Zip… however after adding your address, the State disappears, resulting in an error.

Adding New Address (Including the State):
enter image description here

State Not added, resulting in error:
enter image description here

So far the only way to counter this is to first go into your account and add the new address first, then go to checkout and select the address.

Any ideas?

commerce – How to patch the CheckoutCartEventSubscriber in Checkout submodule?

I want to patch CheckoutCartEventSubscriber.php, which can be found in /web/modules/contrib/commerce/modules/checkout/src/EventSubscriber when installed via composer.

So I cloned Commerce from the drupal.org git repository, navigated to the /modules/checkout/src/, and found that there is no EventSubscriber directory. All the other directories that can be found in the composer install exist except EventSubscriber.

The github repo browser doesn’t show the EventSubscriber directory, either.

So where is this directory? How can I find the file to patch it?

magento2.3 – How to add Custom buttons to checkout from

Hi am trying to add a custom button to the checkout form but its not working

below is my code see if any one can provide some solution

$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children']['yes'] = [
            'component' => 'Magento_Ui/js/form/element/abstract',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'customEntry' => null,
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/submit',
                // 'tooltip' => [
                //     'description' => 'this is custom var field',
                // ],
            ],

            'dataScope' => 'shippingAddress.custom_attributes.yes' ,
            'label' => 'Yes',
            'provider' => 'checkoutProvider',
            'sortOrder' => 62,
            'validation' => [
                'required-entry' => false
            ],
            'options' => [],
            'filterBy' => null,
            'customEntry' => null,
            'visible' => true,
        ];