<?php
/*
 * @category: Magepow
 * @copyright: Copyright (c) 2014 Magepow (http://www.magepow.com/)
 * @licence: http://www.magepow.com/license-agreement
 * @author: MichaelHa
 * @create date: 2019-06-14 17:19:50
 * @LastEditors: MichaelHa
 * @LastEditTime: 2019-06-29 12:46:59
 */
?>
<?php
$exist = $block->getProductCollection()->getSize();
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
$items = $block->getProductCollection();
$image = 'related_products_list';
?>
<?php if ($exist) : ?>
    <div id="ajax-suggest" class="block products-ordered">
        <div class="block-title title">
            <strong id="block-products-ordered-heading" role="heading" aria-level="2">
                <?php echo $block->escapeHtml($block->getTitle()); ?>
            </strong>
        </div>
        <div class="block-content content" aria-labelledby="block-products-ordered-heading">
            <div class="ajax-owl-loading"></div>
            <div class="wrapper grid products-grid products-products-ordered">
                <ol class="ajax-cart-owl-carousel">
                    <?php $iterator = 1; ?>
                    <?php $numberItem = count($items); ?>
                    <?php foreach ($items as $_item) : ?>
                        <?php echo($iterator++ == 1) ? '<div class="item">' : '</div><div class="item">' ?>
                        <div class="product-item-info">
                            <a
                            href="<?php echo $block->escapeUrl($block->getProductUrl($_item)); ?>"
                            class="product photo product-item-photo"
                            >
                            <?php echo $block->getImage($_item, $image)->toHtml(); ?>
                        </a>
                        <div class="product details product-item-details">
                            <strong class="product name product-item-name">
                                <a
                                class="product-item-link"
                                title="<?php echo $block->escapeHtml($_item->getName()); ?>"
                                href="<?php echo $block->escapeUrl($block->getProductUrl($_item)); ?>"
                                >
                                <?php echo $block->escapeHtml($_item->getName()); ?>
                            </a>
                        </strong>

                        <?php /* @escapeNotVerified */ echo $block->getProductPrice($_item); ?>

                        <?php if ($templateType) : ?>
                            <?php echo $block->getReviewsSummaryHtml($_item, $templateType) ?>
                        <?php endif; ?>
                    </div>
                    <div class="actions-primary">
                        <?php if ($_item->isSaleable()) : ?>
                            <?php if ($_item->getTypeInstance()->hasRequiredOptions($_item)) : ?>
                            <button
                            class="action tocart primary"
                            data-mage-init='{
                            "redirectUrl": {
                            "url": "<?php
                            echo $block->escapeUrl(
                            $block->getAddToCartUrl($_item)
                            );
                            ?>"
                        }
                    }'
                    type="button"
                    title="<?php
                    echo $block->escapeHtml(__('Add to Cart')); ?>"
                    data-product-id="<?php echo $block->escapeHtml($_item->getId()); ?>"
                    >
                    <span><?php
                    echo $block->escapeHtml(__('Add to Cart')); ?></span>
                </button>
                <?php else : ?>
                    <?php
                    $postDataHelper = $block->getPostDataHelper();
                    $postData = $postDataHelper->getPostData(
                        $block->getAddToCartUrl($_item),
                        ['product' => $_item->getEntityId()]
                    );
                    ?>
                    <button
                    class="action tocart primary"
                    data-post='<?php
                    echo $block->escapeHtml($postData); ?>'
                    type="button" title="<?php
                    echo $block->escapeHtml(__('Add to Cart')); ?>"
                    >
                    <span><?php
                    echo $block->escapeHtml(__('Add to Cart')); ?></span>
                </button>
            <?php endif; ?>
            <?php else : ?>
                <?php if ($_item->getIsSalable()) : ?>
                    <div class="stock available">
                        <span><?php
                        echo $block->escapeHtml(__('In stock')); ?></span>
                    </div>
                    <?php else : ?>
                        <div class="stock unavailable">
                            <span><?php
                            echo $block->escapeHtml(__('Out of stock')); ?></span>
                        </div>
                    <?php endif; ?>
                <?php endif; ?>
            </div>
        </div>
        <?php echo($iterator == $numberItem + 1) ? '</div>' : '' ?>
    <?php endforeach ?>
</ol>
</div>
</div>
</div>

<?php echo $block->getChildHtml('ajaxcart.popup.ajax.suggest'); ?>

<script type="text/x-magento-init">
    {
        "#ajax-suggest": {
        "magepowProductSuggest": {
        "itemsNumber": <?php echo $block->escapeJsQuote($numberItem); ?>
    }
}
}
</script>
<?php endif; ?>