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

// @codingStandardsIgnoreFile

/**
 * Product view template
 *
 * @var $block \Magento\Catalog\Block\Product\View
 */
?>
<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$form = $this->getLayout()->getBlock('product.info');
$filterTypes = ['bundle'];
$showFormTag = ($this->getData('has_form_tag') && (!in_array($_product->getTypeId(), $filterTypes)));
$this->setData('show_form_tag', $showFormTag);
?>
<?php if ($showFormTag && $form) : ?>
<form data-product-sku="<?= $block->escapeHtml($_product->getSku()) ?>" action="<?php echo $form->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if ($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php endif ?>
    <?= $block->getChildHtml() ?>
<?php if ($showFormTag) : ?>
</form>
<script>
    require([
        'jquery',
        'priceBox'
    ], function($){
        var dataPriceBoxSelector = '[data-role=priceBox]',
            dataProductIdSelector = '[data-product-id=<?php echo $block->escapeHtml($_product->getId())?>]',
            priceBoxes = $(dataPriceBoxSelector + dataProductIdSelector);

        priceBoxes = priceBoxes.filter(function(index, elem) {
            return !$(elem).find('.price-from').length;
        });

        priceBoxes.priceBox({'priceConfig': <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>});
    });
</script>
<?php endif ?>