<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@buy-addons.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author    Buy-Addons <contact@buy-addons.com>
*  @copyright 2007-2020 PrestaShop SA
*  @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
* @since 1.6
*/

class AskforaquotemodulquantitymaxModuleFrontController extends ModuleFrontController
{
    public function run()
    {
        parent::init();
        parent::initHeader();
        parent::initContent();
        $info_product = array();
        $id_attr_product = Tools::getValue('id_attr_product');
        $id_pro_have_select = Tools::getValue('id_pro_have_select');
        $id_lang = $this->context->language->id;
        $id_shop = Tools::getValue('jsshopid');
        $this->context->shop->id = $id_shop;
        if (empty($id_attr_product)) {
            $quantity = StockAvailable::getQuantityAvailableByProduct($id_pro_have_select, null, $id_shop);
        } elseif ($id_attr_product == '-1') {
            $quantity = 0;
        } else {
            $product = new Product($id_pro_have_select, false, $id_lang);
            $product_attr = $product->getAttributeCombinationsById($id_attr_product, $id_lang);
            foreach ($product_attr as $value) {
                $quantity = $value['quantity'];
            }
        }
        $info_product['quantity'] = $quantity;
        echo Tools::jsonEncode($info_product);
    }
}
