Your IP : 216.73.216.189


Current Path : /var/www/magento.test.indacotrentino.com/www/buy/
Upload File :
Current File : /var/www/magento.test.indacotrentino.com/www/buy/indaco-autumnus-BBGet.php

<?php
require __DIR__ . '/../app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$state = $objectManager->get(Magento\Framework\App\State::class);
$state->setAreaCode('frontend');

$redirectFactory = $objectManager->get(\Torresani\QrCodeRedirect\Model\RedirectFactory::class);
$codeToSearch = $_GET['k'];
$storeId = 2;

$redirectModel = $redirectFactory->create();
$redirectCollection = $redirectModel->getCollection();
$redirectCollection->addFieldToFilter('store_id', $storeId);
$redirectCollection->addFieldToFilter('code', $codeToSearch);

if ($redirectCollection->getSize() > 0) {
    $record = $redirectCollection->getFirstItem();
    $idCategory = $record->getCategoryId();

    $categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');
    $storeId = 2;
    $store = $objectManager->create(\Magento\Store\Model\Store::class)->load($storeId);
    $category = $categoryFactory->create()->setStore($store)->load($idCategory);
    $categoryProducts = $category->getProductCollection()->addAttributeToSelect('*');
    $idProducts = '';
    foreach ($categoryProducts as $product) {
        $idProducts .= $product->getId(). ',';
    }
    $idProducts = substr($idProducts, 0, -1);
    $accessKey = '6733f1af4dbc12f39ab4812ab0b0048cb15882db';
    $url = 'https://autumnus.indacotrentino.com/bb/loadbutton/index/access/6733f1af4dbc12f39ab4812ab0b0048cb15882db';
    $baseUrl = 'https://autumnus.indacotrentino.com/';
    $staticUrl = 'https://autumnus.indacotrentino.com/media/buybutton';

    insertVisitLog(2, null, $codeToSearch, $_SERVER['HTTP_REFERER'] ?? '', 'getProduct');

    $string = <<<EOT
    <iframe srcdoc="<div id='buybutton-init'></div><script>
    (function(d, s, id) {
        var js, bjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s);
        js.id = id;
        js.async = true;
        js.src = '$url';
        js.onload = function() {
            new BuyButton({
                redirectToProduct: '0',
                locale: 'it-it',
                currency_code: 'EUR',
                storeId: '2',
                productIds: '$idProducts',
                baseUrl: '$baseUrl',
                styles: '@import url(\'https://fonts.googleapis.com/css2?family=Josefin+Sans&display=swap\');.buybutton-container {  background: #FFFFFF;}.bb-cart-count{left:40px;top:5px;}.rango-cart:before{content: inherit;}.rango-cart{background-image: url(https://autumnus.trento.it/images/carrello.png);width: 40px;height: 40px;background-size: contain;background-repeat: no-repeat;background-position: center center;display: block;}.buybutton-item.width-less-then-890{width:46%;}.buybutton-item.width-less-then-638{width:96%;}.buybutton-item.width-less-then-383{width:100%;}.buybutton-item-image img{width:initial;height:initial;max-height:100%;max-width:100%;}.buybutton-modal{overflow:auto}.buybutton-modal-image{display:flex; justify-content: center;}.buybutton-modal-image img{width:initial;max-width:100%;max-height:100%;padding-top:50px;}.buybutton-item {  text-align: center;  background: #FFFFFF;  width: 21%; margin:2%;}.buybutton-message {font-family: \'Josefin Sans\', Arial, Helvetica, sans-serif;font-size: 18px;display:flex;justify-content: center;}.buybutton-item-name {font-family: \'Josefin Sans\', Arial, Helvetica, sans-serif;  font-size: 18px;  color: #000; font-weight: bold;}.buybutton-add{height:30px;}.buybutton-item-price {  font-family: \'Josefin Sans\', Arial, Helvetica, sans-serif;  font-size: 18px;  color: #672146;}.buybutton-cart { background: #FFA300; border-radius:50px;display:flex;align-items: center; }.buybutton-item-view > button, .buybutton-product-addtocart > button.buybutton-primary {  background: #FFA300; border: 1px solid #FFA300; border-radius: 500px;  font-family: \'Josefin Sans\', Arial, Helvetica, sans-serif;  font-size: 16px;  color: #FFF;}.bb-cart-checkout > .button {  font-family: \'Josefin Sans\', Arial, Helvetica, sans-serif;  color: #fff;  background: #FFA300;  border-color: #FFA300;}.buybutton-product-price,.bb-cart-item-price {  font-family: \'Josefin Sans\', Arial, Helvetica, sans-serif;  font-size: 18px;  color: #000; margin-bottom: 10px;}.bb-cart-item-name,.buybutton-product-name {  font-family: \'Josefin Sans\', Arial, Helvetica, sans-serif;  font-size: 15px;  color: #000; text-transform: uppercase; margin-bottom:10px}.bb-cart-item-name, .bb-cart-item-price{color:white}.buybutton-product-sku,.buybutton-product-description {  font-family: \'Josefin Sans\', Arial, Helvetica, sans-serif;  font-size: 18px;  color: #666666; padding-top:25px;}.quantity-button{background-color: #ffa300; border-radius: 50px; width: 30px; border: 0; margin: 0px 5px; color: #ffffff; font-size: 22px;}@media screen and (max-width: 768px) {.buybutton-modal{display:flex;flex-direction: column;margin:2.5%;width:90%}.buybutton-modal-left,.buybutton-modal-right{width:100%;}.buybutton-modal-container {position:fixed;}.buybutton-add{flex-direction: column;margin-bottom:45px;}.quantity-control{margin-bottom:15px;}}.bb-mini-cart-container{width:400px;max-width:400px;background:#672146;color:white;}.bb-cart-wrapper{font-family: \'Josefin Sans\', Arial, Helvetica, sans-serif;}.no-data-found{font-family: \'Josefin Sans\', Arial, Helvetica, sans-serif;color:white;}.bb-mini-cart-head .buybutton-modal-close{color:white}',
                vButtonText: 'Vedi dettaglio',
                miniCartText: 'Carrello',
                addToCartText: 'Aggiungi al carrello',
                buyNowText: 'compra',
                itemInCartText: 'Prodotti nel carrello',
                cButtonText: 'Procedi al check out',
                noItemFoundText: 'Nessun prodotto nel carrello',
                shippingInfoText: '',
                qtyText: 'Qty',
                subTotalText: 'Totale carrello',
                designTemplate: 1,
                staticUrl: '$staticUrl',
                accessKey: '$accessKey'
            });
        };
        bjs.parentNode.insertBefore(js, bjs);
    }(document, 'script', 'buybutton-js'));</script>" id='bb-iframe' width='100%' height='500' frameBorder='0'></iframe>
    <script>
    setTimeout(function() {
        let iframe = document.getElementById("bb-iframe");
        iframe.onload = function() {
            iframe.style.height = iframe.contentWindow.document.body.scrollHeight + 'px';
        };
    }, 5000);
    </script>
<script>var _paq = window._paq = window._paq || [];_paq.push(['trackPageView']);_paq.push(['enableLinkTracking']);_paq.push(['setCookieSameSite', 'None']);(function() {var u="//matomo.38121.it/";_paq.push(['setTrackerUrl', u+'matomo.php']);_paq.push(['setSiteId', '3']);var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);})();</script>
EOT;

    echo $string;
} else {
    echo "Nessun record trovato con il codice '$codeToSearch'";
}
function insertVisitLog($storeId, $customerId, $code, $url, $action) {
    try {
        $ip = null;
        if(!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        }
        else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        $operating_system = explode(";",$user_agent)[1]."";
        $userAgentParts = explode(" ", $user_agent);
        $browser = end($userAgentParts);
        $data = [
            [
                'store_id' => $storeId, 'customer_id' => $customerId, 'code' => $code, 'url' => $url,
                'action' => $action, 'ip' => $ip, 'user_agent' =>$_SERVER['HTTP_USER_AGENT'], 'operating_system' =>$operating_system, 'browser' =>$browser,
            ]
        ];
        $configFile = BP . '/app/etc/env.php';
        $config = include $configFile;

        $dbConfig = $config['db']['connection']['default'];
        $connection = new \mysqli($dbConfig['host'], $dbConfig['username'], $dbConfig['password'], $dbConfig['dbname']);
        if ($connection->connect_error) {
            die("Error in connection db: " . $connection->connect_error);
        }
        $tableName = 'qrcoderedirect_visit';
        $insertQuery = "INSERT INTO {$tableName} (store_id, customer_id, code, url, action, ip, user_agent, operating_system, browser) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";

        $stmt = $connection->prepare($insertQuery);
        if ($stmt === false) {
            die("Error in query staetment: " . $connection->error);
        }
        $stmt->bind_param("iisssssss", $storeId, $customerId, $code, $url, $action, $ip, $_SERVER['HTTP_USER_AGENT'], $operating_system, $browser);
        $result = $stmt->execute();
        if ($result === false) {
            die("Error in the query: " . $stmt->error);
        }
        $stmt->close();
        $connection->close();
    } catch (\Exception $e) {
        // Gestione delle eccezioni
        echo "Errore: " . $e->getMessage();
    }

}