Skip to content
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

imagento/magento2#8515: Downloadable product is available for downloa… #8917

Merged
merged 4 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
if ($item->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
|| $item->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
) {
if (in_array($item->getStatusId(), $expiredStatuses)) {
if ($order->isCanceled() || in_array($item->getStatusId(), $expiredStatuses)) {
$downloadableItemsStatuses[$item->getId()] = $linkStatuses['expired'];
} else {
$downloadableItemsStatuses[$item->getId()] = $linkStatuses['avail'];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Magento\Downloadable\Model\Observer;

/**
* Integration test for case, when customer is able to download
* downloadable product, after order was canceled.
*/
class SetLinkStatusObserverTest extends \PHPUnit_Framework_TestCase
{
/**
* Object manager
* @var \Magento\Framework\ObjectManagerInterface
*/
protected $objectManager;

/**
* Order repository
* @var \Magento\Sales\Model\OrderRepository
*/
protected $orderRepository;

/**
* Initialization of dependencies
*/
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->orderRepository = $this->objectManager->get(
\Magento\Sales\Api\OrderRepositoryInterface::class
);
}

/**
* Asserting, that links status is expired after canceling of order.
*
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
* @magentoDataFixture Magento/Downloadable/_files/product_downloadable_with_files.php
* @magentoDataFixture Magento/Downloadable/_files/order_with_downloadable_product_with_links.php
*/
public function testCheckStatusOnOrderCancel()
{
/** @var \Magento\Sales\Model\Order $order */
$order = $this->orderRepository->get(1);

$orderItems = $order->getAllItems();
$items = array_values($orderItems);
/** @var \Magento\Sales\Model\Order\Item $orderItem */
$orderItem = array_shift($items);

/** @var \Magento\Sales\Model\Service\InvoiceService $invoiceService */
$invoiceService = $this->objectManager->create(
\Magento\Sales\Model\Service\InvoiceService::class
);

/** @var \Magento\Sales\Model\Order\Invoice $invoice */
$invoice = $invoiceService->prepareInvoice($order);

/** Register invoice */
$invoice->register();
$invoice->save();

/** @var \Magento\Framework\DB\Transaction $transactionService */
$transactionService = $this->objectManager->create(
\Magento\Framework\DB\Transaction::class
);
$transactionService->addObject($invoice)
->addObject($invoice->getOrder())
->save();

/** Canceling order to reproduce test case */
$order->setState(\Magento\Sales\Model\Order::STATE_CANCELED);
$order->save();

/** @var \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\Collection $linkCollection */
$linkCollection = $this->objectManager->create(
\Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\CollectionFactory::class
)->create();

$linkCollection->addFieldToFilter('order_item_id', $orderItem->getId());

/** @var \Magento\Downloadable\Model\Link\Purchased\Item $linkItem */
foreach ($linkCollection->getItems() as $linkItem) {
$this->assertEquals(
\Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_EXPIRED,
$linkItem->getStatus()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$billingAddress = $objectManager->create(
\Magento\Sales\Model\Order\Address::class,
[
'data' => [
'firstname' => 'guest',
'lastname' => 'guest',
'email' => '[email protected]',
'street' => 'street',
'city' => 'Los Angeles',
'region' => 'CA',
'postcode' => '1',
'country_id' => 'US',
'telephone' => '1',
]
]
);
$billingAddress->setAddressType('billing');

$payment = $objectManager->create(
\Magento\Sales\Model\Order\Payment::class
);
$payment->setMethod('checkmo');

$orderItem = $objectManager->create(
\Magento\Sales\Model\Order\Item::class
);
$orderItem->setProductId(
1
)->setQtyOrdered(
1
)->setProductType(
\Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
)->setProductOptions(
[
'links' => [1]
]
);

$order = $objectManager->create(
\Magento\Sales\Model\Order::class
);

$order->setCustomerEmail('[email protected]')
->addItem(
$orderItem
)->setIncrementId(
'100000001'
)->setCustomerIsGuest(
true
)->setStoreId(
1
)->setEmailSent(
0
)->setBillingAddress(
$billingAddress
)->setPayment(
$payment
);
$order->save();
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
require __DIR__ . '/product_downloadable_rollback.php';
require __DIR__ . '/../../../Magento/Sales/_files/default_rollback.php';