Пример #1
0
function cw_ab_get_cms_restrict_attributes($contentsection_id)
{
    global $tables;
    $contentsection_id = intval($contentsection_id);
    $_restricted_attributes = cw_ab_get_cms_restrictions($contentsection_id, 'A', 'attribute_id');
    $restricted_attributes = array();
    foreach ($_restricted_attributes as $attr_entry) {
        $restricted_attributes[] = array('attribute_id' => $attr_entry['attribute_id'], 'operation' => $attr_entry['operation'], 'value' => array($attr_entry['value_id'] > 0 ? $attr_entry['value_id'] : $attr_entry['value']));
    }
    return $restricted_attributes;
}
function cw_ps_on_cms_check_restrictions_PS($data)
{
    static $active_offers_ids;
    if (!isset($active_offers_ids)) {
        $active_offers = cw_ps_get_offers();
        $active_offers_ids = array_column($active_offers, 'offer_id');
    }
    // Get offers related to cms
    $cms_offers = cw_ab_get_cms_restrictions($data['contentsection_id'], 'PS');
    if (empty($cms_offers)) {
        return true;
    }
    $cms_offers_ids = array_column($cms_offers, 'object_id');
    // Check if at least one offer is active now
    $is_valid = array_intersect($cms_offers_ids, $active_offers_ids);
    return $is_valid;
}
<?php

if ($REQUEST_METHOD == 'GET') {
    $offers = cw_ps_get_offers(false);
    $smarty->assign('offers', $offers);
    //var_dump($offers);
    if ($contentsection_id) {
        $cms_offers = cw_ab_get_cms_restrictions($contentsection_id, 'PS');
        $smarty->assign('cms_offers', array_column($cms_offers, 'object_id'));
    }
    if ($contentsections_filter['offers']) {
        $smarty->assign('cms_offers', $contentsections_filter['offers']);
    }
}
function cw_manufacturers_on_cms_check_restrictions_M($data)
{
    global $tables, $product_id;
    static $manufacturer_attribute_id;
    if (is_null($manufacturer_attribute_id)) {
        $manufacturer_attribute_id = cw_call('cw_attributes_get_attribute_by_field', array('manufacturer_id'));
    }
    if (isset($product_id)) {
        $allowed_manufacturer_ids = cw_ab_get_cms_restrictions($data['contentsection_id'], 'M', 'manufacturer_id');
        if (empty($allowed_manufacturer_ids)) {
            return true;
        }
        $allowed_manufacturer_ids = array_column($allowed_manufacturer_ids, 'manufacturer_id');
        $product_manufacturer_id = cw_query_first_cell("SELECT value FROM {$tables['attributes_values']} WHERE item_id = '" . $product_id . "' and item_type='P' AND attribute_id='{$manufacturer_attribute_id}'");
        if (!empty($allowed_manufacturer_ids) && is_array($allowed_manufacturer_ids) && !empty($product_manufacturer_id)) {
            if (!in_array($product_manufacturer_id, $allowed_manufacturer_ids)) {
                return false;
            }
        }
    }
    return true;
}