1

This screenshot is for "My downloadable products" section in customer dashboard: enter image description here According to above screenshots I have added "Test" button and right now I am keeping this button disabled

I am using Magento 2.2.3

I want to enable this button after 1 day or let's say 1 hour of order creation date(which is 29/9/2018 given in the screenshots). So how can I achieve this.

I have edited below file:

app/design/frontend/My_vendor/my_theme/Magento_Downloadable/templates/customer/products/list.phtml

 <?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * @var $block \Magento\Downloadable\Block\Customer\Products\ListProducts
 */
?>

<?php $_items = $block->getItems(); ?>
<?php if (count($_items)): ?>
    <div class="table-wrapper downloadable-products">
        <table id="my-downloadable-products-table" class="data table table-downloadable-products">
            <caption class="table-caption"><?= /* @escapeNotVerified */ __('Downloadable Products') ?></caption>
            <thead>
                <tr>
                    <th scope="col" class="col id"><?= /* @escapeNotVerified */ __('Order #') ?></th>
                    <th scope="col" class="col date"><?= /* @escapeNotVerified */ __('Date') ?></th>
                    <th scope="col" class="col title"><?= /* @escapeNotVerified */ __('Title') ?></th>
                    <th scope="col" class="col id"><?= /* @escapeNotVerified */ __('Download Link') ?></th>
                    <th scope="col" class="col id"><?= /* @escapeNotVerified */ __('Support') ?></th>
                    <?php /*?><th scope="col" class="col status"><?=  __('Status') ?></th>
                    <th scope="col" class="col remaining"><?=  __('Remaining Downloads') ?></th><?php */?>
                </tr>
            </thead>
            <tbody>
            <?php foreach ($_items as $_item): ?>
                <tr>
                    <td data-th="<?= $block->escapeHtml(__('Order #')) ?>" class="col id">
                        <a href="<?= /* @escapeNotVerified */ $block->getOrderViewUrl($_item->getPurchased()->getOrderId()) ?>"
                            title="<?= $block->escapeHtml(__('View Order')) ?>">
                            <?= /* @escapeNotVerified */ $_item->getPurchased()->getOrderIncrementId() ?>
                        </a>
                    </td>
                    <td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date"><?= /* @escapeNotVerified */ $block->formatDate($_item->getPurchased()->getCreatedAt()) ?></td>
                    <td data-th="<?= $block->escapeHtml(__('Title')) ?>" class="col title">
                        <strong class="product-name"><?= $block->escapeHtml($_item->getPurchased()->getProductName()) ?></strong>
                    </td>
                    <td data-th="<?= $block->escapeHtml(__('Download Link')) ?>" class="col id">
                        <?php if ($_item->getStatus() == \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_AVAILABLE): ?>
                        <a href="<?= /* @escapeNotVerified */ $block->getDownloadUrl($_item) ?>" title="<?= $block->escapeHtml(__('Start Download')) ?>" class="action download" <?= $block->getIsOpenInNewWindow() ? 'onclick="this.target=\'_blank\'"' : '' ?>><?= $block->escapeHtml($_item->getLinkTitle()) ?></a>
                        <?php endif; ?>
                    </td>
                    <td data-th="<?= $block->escapeHtml(__('Test')) ?>" class="col id">
                        <button type="submit" title="test" class="" disabled="disabled"><span>Test</span></button>
                    </td>
                    <?php /*?><td data-th="<?= $block->escapeHtml(__('Status')) ?>" class="col status"><?=  __(ucfirst($_item->getStatus())) ?></td><?php */?>
                    <?php /*?><td data-th="<?= $block->escapeHtml(__('Remaining Downloads')) ?>" class="col remaining"><?=  $block->getRemainingDownloads($_item) ?></td><?php */?>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php if ($block->getChildHtml('pager')): ?>
        <div class="toolbar downloadable-products-toolbar bottom">
            <?= $block->getChildHtml('pager') ?>
        </div>
    <?php endif; ?>
<?php else: ?>
    <div class="message info empty"><span><?= /* @escapeNotVerified */ __('You have not purchased any downloadable products yet.') ?></span></div>
<?php endif; ?>

<div class="actions-toolbar">
    <div class="secondary">
        <a href="<?= $block->escapeUrl($block->getBackUrl()) ?>" class="action back">
            <span><?= /* @escapeNotVerified */ __('Back') ?></span>
        </a>
    </div>
</div>

So which condition I have to add in order to enable the button after certain period of time of order creation?

  • @Sukumar Gorai Now I want to add a particular product in cart when clicking on "Test" button? So do you have any idea about this? – Chintan Kaneriya Oct 1 '18 at 11:00
1

Copy the below file:

/vendor/magento/module-downloadable/view/frontend/templates/customer/products/list.phtml

to your theme location like below:

/app/design/frontend/Vendor/theme/Magento_Downloadable/templates/customer/products/list.phtml

And put the below contents to your list.phtml:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * @var $block \Magento\Downloadable\Block\Customer\Products\ListProducts
 */
?>
<?php $_items = $block->getItems(); ?>
<?php 
    $to = date("Y-m-d h:i:s"); echo '<br>'; // current time
    $from = strtotime('-1 hour', strtotime($to));
    $from = date('Y-m-d h:i:s', $from); // 1 hour before
?>
<?php if (count($_items)): ?>
    <div class="table-wrapper downloadable-products">
        <table id="my-downloadable-products-table" class="data table table-downloadable-products">
            <caption class="table-caption"><?= /* @escapeNotVerified */ __('Downloadable Products') ?></caption>
            <thead>
                <tr>
                    <th scope="col" class="col id"><?= /* @escapeNotVerified */ __('Order #') ?></th>
                    <th scope="col" class="col date"><?= /* @escapeNotVerified */ __('Date') ?></th>
                    <th scope="col" class="col title"><?= /* @escapeNotVerified */ __('Title') ?></th>
                    <th scope="col" class="col status"><?= /* @escapeNotVerified */ __('Status') ?></th>
                    <th scope="col" class="col remaining"><?= /* @escapeNotVerified */ __('Remaining Downloads') ?></th>
                    <th scope="col" class="col support"><?= /* @escapeNotVerified */ __('Support') ?></th>
                </tr>
            </thead>
            <tbody>
            <?php foreach ($_items as $_item): ?>
                <tr>
                    <td data-th="<?= $block->escapeHtml(__('Order #')) ?>" class="col id">
                        <a href="<?= /* @escapeNotVerified */ $block->getOrderViewUrl($_item->getPurchased()->getOrderId()) ?>"
                            title="<?= $block->escapeHtml(__('View Order')) ?>">
                            <?= /* @escapeNotVerified */ $_item->getPurchased()->getOrderIncrementId() ?>
                        </a>
                    </td>
                    <td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date"><?= /* @escapeNotVerified */ $block->formatDate($_item->getPurchased()->getCreatedAt()) ?></td>
                    <td data-th="<?= $block->escapeHtml(__('Title')) ?>" class="col title">
                        <strong class="product-name"><?= $block->escapeHtml($_item->getPurchased()->getProductName()) ?></strong>
                        <?php if ($_item->getStatus() == \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_AVAILABLE): ?>
                        <a href="<?= /* @escapeNotVerified */ $block->getDownloadUrl($_item) ?>" title="<?= $block->escapeHtml(__('Start Download')) ?>" class="action download" <?= $block->getIsOpenInNewWindow() ? 'onclick="this.target=\'_blank\'"' : '' ?>><?= $block->escapeHtml($_item->getLinkTitle()) ?></a>
                        <?php endif; ?>
                    </td>
                    <td data-th="<?= $block->escapeHtml(__('Status')) ?>" class="col status"><?= /* @escapeNotVerified */ __(ucfirst($_item->getStatus())) ?></td>
                    <td data-th="<?= $block->escapeHtml(__('Remaining Downloads')) ?>" class="col remaining"><?= /* @escapeNotVerified */ $block->getRemainingDownloads($_item) ?></td>
                    <td data-th="<?= $block->escapeHtml(__('Support')) ?>" class="col remaining"><button <?php if($_item->getPurchased()->getCreatedAt()>$from){ echo 'disabled'; } ?>>Test</button></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php if ($block->getChildHtml('pager')): ?>
        <div class="toolbar downloadable-products-toolbar bottom">
            <?= $block->getChildHtml('pager') ?>
        </div>
    <?php endif; ?>
<?php else: ?>
    <div class="message info empty"><span><?= /* @escapeNotVerified */ __('You have not purchased any downloadable products yet.') ?></span></div>
<?php endif; ?>

<div class="actions-toolbar">
    <div class="secondary">
        <a href="<?= $block->escapeUrl($block->getBackUrl()) ?>" class="action back">
            <span><?= /* @escapeNotVerified */ __('Back') ?></span>
        </a>
    </div>
</div>

I have added a logic for 1 hour. You can change it according to your requirement.

$from = strtotime('-1 hour', strtotime($to));
$from = date('Y-m-d h:i:s', $from); // 1 hour before

This is the section where you can change the logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.