Skip to content

Fixed #22545 Status downloadable product stays pending after succesfu… #22658

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

Merged

Conversation

shikhamis11
Copy link
Member

Fixed #22545 Status downloadable product stays pending after succesfull payment

When a downloadable product has been order and paid for download status should automatically become available. Status remains pending although order is invoiced and completed automatically by payment processor. When order is invoiced from admin it all works.

Preconditions (*)

  1. Magento 2.3.1 CE
  2. PHP 7.2

Steps to reproduce (*)

  1. Setup Magento site with demo contents
  2. Order Item Status to Enable Downloads->Invoiced
  3. Setup Payment for instance Paypal
  4. Make purchase of downloadable product with payment method Paypal
  5. Make sure payment is succesfull (Order status is completed)

Expected result (*)

  1. Download link should be available in customer account
  2. Status of downloadable product should be available

Actual result (*)

  1. In customer account order status is completed
  2. In customer account downloadable product is pending

When an order is placed and in Magento admin the order is invoiced the it works as it should. So somehow downloadable status is not changed when an order is automatically set to completed when payment is succesfull.

This issue occured only after upgrading to Magento 2.3.1 in 2.3.0 it all worked like it should.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@m2-assistant
Copy link

m2-assistant bot commented May 4, 2019

Hi @shikhamis11. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation


$linkstatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING;
if( $orderStatusToEnableItem == \Magento\Sales\Model\Order\Item::STATUS_PENDING
|| $orderItem->getOrder()->getStatus() == \Magento\Sales\Model\Order::STATE_COMPLETE){
Copy link
Contributor

@dmytro-ch dmytro-ch May 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should use the getState instead of getStatus method in this case.
Could you please check this point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@@ -131,6 +131,13 @@ public function execute(\Magento\Framework\Event\Observer $observer)
ScopeInterface::SCOPE_STORE
);
$linkPurchased->setLinkSectionTitle($linkSectionTitle)->save();

$linkstatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please change the variable name to $linkStatus?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@@ -131,6 +131,13 @@ public function execute(\Magento\Framework\Event\Observer $observer)
ScopeInterface::SCOPE_STORE
);
$linkPurchased->setLinkSectionTitle($linkSectionTitle)->save();

$linkstatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING;
if( $orderStatusToEnableItem == \Magento\Sales\Model\Order\Item::STATUS_PENDING
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix minor styling issues for if statement according to PSR-2 standard (spacings etc.).
An if structure should look like the following:

if ($a == $b
    || $b == $c
    || $c == $d
) {
    // code here
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@shikhamis11
Copy link
Member Author

@dmytro-ch, Thanks for your review.
I have updated changes Please check

@dmytro-ch
Copy link
Contributor

dmytro-ch commented May 13, 2019

@shikhamis11, could you please also check and fix the static test failures.
Once the changes are applied, please squash all commits into a single one in order to cleanup history.
Thank you!

@shikhamis11
Copy link
Member Author

sure I will

@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-5157 has been created to process this Pull Request

@soleksii
Copy link

Hi @shikhamis11 !

I cannot reproduce the issue #22545 .

Manual testing scenario:

  1. Create Order with downloadable product (PayPay Express Checkout);
  2. Automatically create invoice;

Actual result:
My orders:
screen2
My Downloadable Products:
screen1

Could you take a look, please?

@shikhamis11
Copy link
Member Author

hello @stoleksiy
I will check and update you

@Robert-Sheahan
Copy link

I have had this problem for a few months now. My website is completely down as customers cannot get downloadable purchase. Just wondering when and how this fix would be released. Thanks.

@shikhamis11
Copy link
Member Author

hello @stoleksiy
I checked at latest magento version not with paypal payment method but with my virtual payment method i.e 'wallet' and after order palce the order status is completed item status is invoiced but the in My Downloadable Products the product link is not available. so I guess issue still exists ..
can you please recheck once at your end

@KooTjoo
Copy link

KooTjoo commented Jun 29, 2019

I have had this problem for a few months now. My website is completely down as customers cannot get downloadable purchase. Just wondering when and how this fix would be released. Thanks.

Well that can be fixed easily by applying the fixes mentioned, next to that it is easy to update this in your DB. No need for a website to be completely down for this.

@Robert-Sheahan
Copy link

I have had this problem for a few months now. My website is completely down as customers cannot get downloadable purchase. Just wondering when and how this fix would be released. Thanks.

Well that can be fixed easily by applying the fixes mentioned, next to that it is easy to update this in your DB. No need for a website to be completely down for this.

KooTjoo, Thanks for the reply. I am a skilled Magento user but not a developer. I see code changes, testing and test failures in these threads. I do not see any quick fix. If there was an option that needed to be changed in the Admin, I could do that, but I am not trained in PHP or how to update code. Yes the site is completely down, as customers buy a product but do not get the link to download the file. They try to buy it again and again until they give up. Then they think I am going to mail something and when nothing arrives I get complaints from PayPal. I contacted dozens of developers for help but only one replied and they required $900 to start looking at it. I keep hoping for a quick fix being that it is such a serious problem. Any ideas? Thanks Bob

@KooTjoo
Copy link

KooTjoo commented Jun 29, 2019

I have had this problem for a few months now. My website is completely down as customers cannot get downloadable purchase. Just wondering when and how this fix would be released. Thanks.
Well that can be fixed easily by applying the fixes mentioned, next to that it is easy to update this in your DB. No need for a website to be completely down for this.

KooTjoo, Thanks for the reply. I am a skilled Magento user but not a developer. I see code changes, testing and test failures in these threads. I do not see any quick fix. If there was an option that needed to be changed in the Admin, I could do that, but I am not trained in PHP or how to update code. Yes the site is completely down, as customers buy a product but do not get the link to download the file. They try to buy it again and again until they give up. Then they think I am going to mail something and when nothing arrives I get complaints from PayPal. I contacted dozens of developers for help but only one replied and they required $900 to start looking at it. I keep hoping for a quick fix being that it is such a serious problem. Any ideas? Thanks Bob

It is a 5 minute fix so $900?????? I don't know how to get into contact with you to discuss further otherwise we could help you.

@jkeller92
Copy link

The Problem is that the Observer Magento\Downloadable\Observer\SaveDownloadableOrderItemObserver sets $linkPurchasedItem status to pending in every case.

We need a function that provides the correct status instead of forcing pending-Status

something like this: (conditions are copied from Magento\Downloadable\Observer\SetLinkStatusObserver)

...

...
/**
* Function provides correct downloadLink Status
*
* @param $orderItem
* @return string
*/
    protected function _getStatus($orderItem)
    {
        $orderStatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING;

        $order = $orderItem->getOrder();

        if (!$order || !$order->getId()) {
            return $orderStatus;
        }

        $orderItemStatusToEnable = $this->_scopeConfig->getValue(
            \Magento\Downloadable\Model\Link\Purchased\Item::XML_PATH_ORDER_ITEM_STATUS,
            ScopeInterface::SCOPE_STORE,
            $order->getStoreId()
        );

        if ($order->getState() == \Magento\Sales\Model\Order::STATE_HOLDED) {
            $orderStatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING;
        } elseif ($order->isCanceled()
            || $order->getState() == \Magento\Sales\Model\Order::STATE_CLOSED
            || $order->getState() == \Magento\Sales\Model\Order::STATE_COMPLETE
        ) {
            $expiredStatuses = [
                \Magento\Sales\Model\Order\Item::STATUS_CANCELED,
                \Magento\Sales\Model\Order\Item::STATUS_REFUNDED,
            ];

            if ($orderItem->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
                || $orderItem->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
            ) {
                if ($order->isCanceled() || in_array($orderItem->getStatusId(), $expiredStatuses)) {
                    $orderStatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_EXPIRED;
                } else {
                    $orderStatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_AVAILABLE;
                }
            }
        } elseif ($order->getState() == \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) {
            $orderStatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING_PAYMENT;
        } elseif ($order->getState() == \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW) {
            $orderStatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PAYMENT_REVIEW;
        } else {
            $availableStatuses = [$orderItemStatusToEnable, \Magento\Sales\Model\Order\Item::STATUS_INVOICED];

            if ($orderItem->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
                    || $orderItem->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
                ) {
                if ($orderItem->getStatusId() == \Magento\Sales\Model\Order\Item::STATUS_BACKORDERED
                        && $orderItemStatusToEnable == \Magento\Sales\Model\Order\Item::STATUS_PENDING
                        && !in_array(
                            \Magento\Sales\Model\Order\Item::STATUS_BACKORDERED,
                            $availableStatuses,
                            true
                        )
                    ) {
                    $availableStatuses[] = \Magento\Sales\Model\Order\Item::STATUS_BACKORDERED;
                }

                if (in_array($orderItem->getStatusId(), $availableStatuses)) {
                    $orderStatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_AVAILABLE;
                }
            }
        }

        return $orderStatus;
    }

@saeohioalpha
Copy link

@stoleksiy I just reported this issue in #23549. It definitely still exists. I also verified it exists on the 2.3-develop instance.

@sivaschenko
Copy link
Member

@magento run Functional Tests build

@engcom-Delta
Copy link
Contributor

✔️ QA passed

@m2-assistant
Copy link

m2-assistant bot commented Jul 7, 2019

Hi @shikhamis11, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@magento-engcom-team magento-engcom-team added this to the Release: 2.3.3 milestone Jul 7, 2019
magento-engcom-team pushed a commit that referenced this pull request Jul 7, 2019
@Robert-Sheahan
Copy link

Great, it looks like a fix is in. I have had this problem for months now. My website is completely down as customers do not get link to downloadable purchase. Just wondering when and how Release 2.3.3 would be released. Thanks.

@sidolov sidolov added the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Status downloadable product stays pending after succesfull payment