Jump to content

Edit History

ps8modules

ps8modules

Hi.

Thank you for the additional information.

No extra module is needed, just a script that will run once a day.

 

Sample: (https://your-shop.pl/myscript.php?token=aBcDeFgHiJkL)

<?php

    header("Access-Control-Allow-Origin: *");

    include('./config/config.inc.php');
    include('./init.php');

    $context = Context::getContext();
    $db = Db::getInstance();
    $token = 'aBcDeFgHiJkL'; // change it
    $urlToken = $_GET['token'];

    if ($token == $urlToken) {

        $expiredDate = date('Y-m-d', strtotime('+1 day'));

        $attributeGroupId = 19; // chnage it

        $where = ' WHERE p.id_product_attribute IS NOT NULL AND a.name <= DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 1 day), \'%Y-%m-%d\') OR name = \''.$expiredDate.'\'';

        $select = 'SELECT a.id_attribute, p.id_product_attribute 
            FROM '._DB_PREFIX_.'attribute_lang a 
            LEFT JOIN '._DB_PREFIX_.'product_attribute_combination p ON (a.id_attribute = p.id_attribute)'
            .$where.
            ' GROUP BY a.id_attribute';

        $getExpiredAttributeValues = $db->executeS($select);

        $toRemove = [];
        $toRemoveAttribute = [];

        if ($getExpiredAttributeValues){ // found expired

            foreach ($getExpiredAttributeValues as $attributeCombination) {
                if ((int) $attributeCombination['id_attribute'] != 0) {
                    $toRemove[] = (int) $attributeCombination['id_product_attribute'];
                    $toRemoveAttribute[] = (int) $attributeCombination['id_attribute'];
                }
            }

            if (!empty($toRemove)) {
                foreach ($toRemove as $remove) {
                    $combination = new Combination($remove);
                    $combination->delete();
                    echo 'Deleted product attribute ID: '.$remove.'<br>';
                }

            }

            if (!empty($toRemoveAttribute)) {
                foreach ($toRemoveAttribute as $removeVal) {
                    $db->delete('attribute', 'id_attribute = '.$removeVal);
                    $db->delete('attribute_lang', 'id_attribute = '.$removeVal);
                    $db->delete('attribute_shop', 'id_attribute = '.$removeVal);
                    echo 'Deleted attribute ID: '.$removeVal.'<br>';
                }
            }
        }
    } 

 

ps8modules

ps8modules

Hi.

Thank you for the additional information.

No extra module is needed, just a script that will run once a day.

×
×
  • Create New...