Skip to content

New Order Status config in payment method is useless #5860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hiephm opened this issue Jul 28, 2016 · 7 comments
Closed

New Order Status config in payment method is useless #5860

hiephm opened this issue Jul 28, 2016 · 7 comments
Assignees
Labels
bug report Component: Sales Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@hiephm
Copy link

hiephm commented Jul 28, 2016

Preconditions

Magento CE 2.1.0

Problem

In payment module that is gateway (support authorize, capture command), setting New Order Status config does not have any effect, new orders still have default status of processing state.

Reason

In \Magento\Sales\Model\Order\Payment::place, the status is get from config:

$orderStatus = $methodInstance->getConfigData('order_status');

which is assumed to be set to order later:

$this->processAction($action, $order);
$orderState = $order->getState() ? $order->getState() : $orderState;
$orderStatus = $order->getStatus() ? $order->getStatus() : $orderStatus;

but in current code, this will never happen since in processAction there is a chain of calls which eventually call:

$message = $this->stateCommand->execute($payment, $amount, $order);

This stateCommand can be either \Magento\Sales\Model\Order\Payment\State\AuthorizeCommand or \Magento\Sales\Model\Order\Payment\State\CaptureCommand, which in its execute method having a code like this:

        $state = Order::STATE_PROCESSING;
        $status = false;
...
        if ($payment->getIsFraudDetected()) {
            $status = Order::STATUS_FRAUD;
        }
        $this->setOrderStateAndStatus($order, $status, $state);

This will always set status to $order (either fraud or default) and cause the above $orderStatus never been set.

Suggestion fix:

I still not sure which place should be fixed, may be eliminate the call to setOrderStateAndStatus will do the job since the order state/status will be set later in Payment::place()

@hiephm
Copy link
Author

hiephm commented Jul 29, 2016

Here is a work around using around plugin for \Magento\Sales\Model\Order\Payment\State\CommandInterface:

    public function aroundExecute(CommandInterface $subject, \Closure $proceed, OrderPaymentInterface $payment, $amount, OrderInterface $order)
    {
        $result = $proceed($payment, $amount, $order);
        if ($payment->getMethod() == '<our payment method code>') {
            $orderStatus = $this->config->getValue('order_status');
            if ($orderStatus && $order->getState() == Order::STATE_PROCESSING) {
                $order->setStatus($orderStatus);
            }
        }

        return $result;
    }

@alena-marchenko alena-marchenko self-assigned this Aug 29, 2016
@alena-marchenko
Copy link

Ho @hiephm

We've created MAGETWO-57846 internal ticket regarding this issue,
Thank you!

@alena-marchenko alena-marchenko added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development 2.1.x labels Aug 30, 2016
@alena-marchenko alena-marchenko removed their assignment Aug 30, 2016
@mcspronko
Copy link
Contributor

Hi @alena-marchenko
This will be a great fix and contribution into all payment methods including built-in and custom ones.

magento-team pushed a commit that referenced this issue Jul 3, 2017
Issues fixed:
- MAGETWO-65422 Write default configs to shared configuration file by app:config:dump
- MAGETWO-69567 [Mainline] - Closing the image view window causes mini-cart to drop down
- MAGETWO-69607 Edition Specific BN-Codes for 2.2.x
- MAGETWO-68936 Billing Agreement page is not loaded if Vault enabled
- MAGETWO-57975 Impossible use ExtensionInterfaceFactory
- MAGETWO-69580 Unstable automated test Magento\Paypal\Test\TestCase\InContextExpressOnePageCheckoutTest failed on variation InContextExpressOnePageCheckoutTestVariation1
- MAGETWO-69110 Incorrect status for order placed within Authorize.net with Fraud Filters Triggered (Filter Actions = Process as normal and report filter(s) triggered)
- MAGETWO-68949 [Github] "We Can't Place The Order" error #9455
- MAGETWO-69112 No request sent to Authorize.net after reordering order in admin
- MAGETWO-69584 Command config:sensitive:set does not work on the cloud
- MAGETWO-57846 [Github] New Order Status config in payment method is useless #5860
- MAGETWO-67632 [Github] Invalid method usage in PayPal NVP callDoReauthorization method #9336
- MAGETWO-63239 [GITHUB] No possibility to save payment transaction details
- MAGETWO-69121 Loader doesn't disappear if Authorize.net transact.dll fails request
- MAGETWO-64518 \Magento\CatalogRule\Model\Indexer\IndexBuilder method "doReindexFull()" causes temporary missing sale prices
- MAGETWO-60533 Data passed to Magento\Framework\ObjectManager\Config\Compiled is not validated
- MAGETWO-70061 Exception on EE installation on environment with default-storage-engine=MyISAM
- MAGETWO-69260 Unable to create shipping label due to error of lb to kg conversion
- MAGETWO-58961 Multiselect text values are not searchable using QuickSearch with ElasticSearch
- MQE-155 [FT] Magento\UrlRewrite\Test\TestCase\CreateProductWithSeveralWebsitesUrlRewriteTest randomly fails on Jenkins
@YevSent
Copy link
Contributor

YevSent commented Jul 3, 2017

Hi, @hiephm, the fix merged into the develop branch.

@leoquijano
Copy link

Hi guys,

I see this is in branch 2.3-developed, and it was backported to 2.1-develop. Is this going to be backported to 2.2 as well?

Thanks!

@JMLucas96
Copy link

JMLucas96 commented Mar 21, 2019

Hi, @hiephm I tried to execute your solution but any breakpoint stops on function when I purchase a new item and an order is created, I need to create a di.xml or something else?
I have this class:

<?php
namespace Compsaonline\OrderState\Model\Order\State;

use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Payment\State\CommandInterface as BaseCommandInterface;

class CommandInterface
{
    /**
     * Set pending order status on order place
     * see https://github.com/magento/magento2/issues/5860
     *
     * @todo Refactor this when another option becomes available
     *
     * @param BaseCommandInterface $subject
     * @param \Closure $proceed
     * @param OrderPaymentInterface $payment
     * @param $amount
     * @param OrderInterface $order
     * @return mixed
     */
    public function aroundExecute(BaseCommandInterface $subject, \Closure $proceed, OrderPaymentInterface $payment, $amount, OrderInterface $order)
    {
        $result = $proceed($payment, $amount, $order);
        if ($payment->getMethod() === '') {
            $orderStatus = Order::STATE_NEW;
            if ($orderStatus && $order->getState() == Order::STATE_PROCESSING) {
                $order->setState($orderStatus)
                    ->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_NEW));
            }
        }
        return $result;
    }
}

And I have this structure in my module:

--Compsaonline
---OrderState
---etc
-----module.xml
---Model
-----State
-------CommandInterface.php
---registration.php

I have Magento2.1.8 CE

@vincentwinkel
Copy link

vincentwinkel commented Apr 23, 2019

@JMLucas96 creating a plugin requires to set up a di.xml containing at least something like:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Model\Order\Payment\State\CommandInterface">
         <plugin name="your_name" type="Your\Module\path\CommandInterface"/>
    </type>
</config>

But this workaround doesn't work neither for me. And because I know flushing 100 times the cache + removing generated files is often not enough to see code updates, I directly put some die() in all the Magento\Sales\Model\Order\Payment\State commands, but vainly.

Magento 2.0 for me (I know...).

mmansoor-magento pushed a commit that referenced this issue Oct 15, 2020
[TSG] Fixes for 2.3 (pr140) (2.3.6-develop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Sales Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests

8 participants