<commit_before><?

include "taxes_desactivate.lib.php";

class products extends _sql_base {

  const sql_table = 'ks_shop_products_list';
  const sql_key   = 'product_id';
  protected $sql_table = self::sql_table;
  protected $sql_key   = self::sql_key;

  static function instanciate($product_id) {
    $products = self::from_ids(array($product_id), false);
    return reset($products);
  }

  static function from_ids($ids, $related_products=true) {
    $where = array (self::sql_key => $ids);
    $products =  self::from_where($where, $related_products);
    return array_sort_deep($products, 'product_id');
  }

  static function from_where($where, $related_products=true){

    $products  =  parent::from_where(__CLASS__, self::sql_table, self::sql_key, $where);
    if(!$products)
        return array();

    $head_products_list = array_keys($products);

    $full_list = self::get_product_tree(array_keys($products));
    $missing   = array_diff($full_list, array_keys($products) );
    if($missing)
      $products  =  parent::from_where(__CLASS__, self::sql_table, self::sql_key, array(self::sql_key => $full_list));

    $verif =  array('product_id' => array_extract($products, 'product_id'));
    sql::select('ivs_shop_products_owners', $verif);
    $owners_list = sql::brute_fetch();
    foreach($owners_list as $owner) {
      $product = $products[$owner['product_id']];
      if(!$product->owners_list)
        $product->owners_list = array();
      $product->owners_list[$owner['user_id']] = $owner;
    }

    sql::select('ivs_shop_meta_products_products', $verif);
    $meta_products_list = sql::brute_fetch();
    foreach($meta_products_list as $meta_product) {
      $product = $products[$meta_product['product_id']];
      if(!$product->meta_products_list)
        $product->meta_products_list = array();
      $product->meta_products_list[$meta_product['meta_product_id']] = $meta_product;
    }

    sql::select("ks_shop_products_specifications", $verif);
    $products_specifications = sql::brute_fetch();
    foreach($products_specifications as $product_spec) {
      $product = $products[$product_spec['product_id']];
      if(!$product->products_specifications)
        $product->products_specifications = array();
      $product->products_specifications[$product_spec['specification_key']] = $product_spec;
    }

    sql::select("ks_shop_products_categories", $verif);
    $products_categories = sql::brute_fetch();
    foreach($products_categories as $product_categ) {
      $product = $products[$product_categ['product_id']];
      if(!$product->products_categories)
        $product->products_categories = array();
      $product->products_categories[$product_categ['category_id']] = $product_categ['category_id'];
      if($product['product_id']) {

      }
    }

   // Vignettes
    foreach($products as $product)
     $product->product_img = "/imgs/".SITE_BASE."/products/{$product['product_id']}";

    // Heritage
    self::product_variations($products);

    if(!$related_products)
      $products = array_intersect_key($products, array_flip($head_products_list));

    return $products;
  }


  private static function product_variations($products) {
<commit_msg>Utilisation possible dans la config d'un masque d'URL pour les vignettes de la boutique. Exemple : <shop imgs_url_mask='http://sharing.activisu.com/storage/distrib/shop/%s.jpg'/><commit_after><?

include "taxes_desactivate.lib.php";

class products extends _sql_base {

  const sql_table = 'ks_shop_products_list';
  const sql_key   = 'product_id';
  protected $sql_table = self::sql_table;
  protected $sql_key   = self::sql_key;

  static function instanciate($product_id) {
    $products = self::from_ids(array($product_id), false);
    return reset($products);
  }

  static function from_ids($ids, $related_products=true) {
    $where = array (self::sql_key => $ids);
    $products =  self::from_where($where, $related_products);
    return array_sort_deep($products, 'product_id');
  }

  static function from_where($where, $related_products=true){

    $products  =  parent::from_where(__CLASS__, self::sql_table, self::sql_key, $where);
    if(!$products)
        return array();

    $head_products_list = array_keys($products);

    $full_list = self::get_product_tree(array_keys($products));
    $missing   = array_diff($full_list, array_keys($products) );
    if($missing)
      $products  =  parent::from_where(__CLASS__, self::sql_table, self::sql_key, array(self::sql_key => $full_list));

    $verif =  array('product_id' => array_extract($products, 'product_id'));
    sql::select('ivs_shop_products_owners', $verif);
    $owners_list = sql::brute_fetch();
    foreach($owners_list as $owner) {
      $product = $products[$owner['product_id']];
      if(!$product->owners_list)
        $product->owners_list = array();
      $product->owners_list[$owner['user_id']] = $owner;
    }

    sql::select('ivs_shop_meta_products_products', $verif);
    $meta_products_list = sql::brute_fetch();
    foreach($meta_products_list as $meta_product) {
      $product = $products[$meta_product['product_id']];
      if(!$product->meta_products_list)
        $product->meta_products_list = array();
      $product->meta_products_list[$meta_product['meta_product_id']] = $meta_product;
    }

    sql::select("ks_shop_products_specifications", $verif);
    $products_specifications = sql::brute_fetch();
    foreach($products_specifications as $product_spec) {
      $product = $products[$product_spec['product_id']];
      if(!$product->products_specifications)
        $product->products_specifications = array();
      $product->products_specifications[$product_spec['specification_key']] = $product_spec;
    }

    sql::select("ks_shop_products_categories", $verif);
    $products_categories = sql::brute_fetch();
    foreach($products_categories as $product_categ) {
      $product = $products[$product_categ['product_id']];
      if(!$product->products_categories)
        $product->products_categories = array();
      $product->products_categories[$product_categ['category_id']] = $product_categ['category_id'];
      if($product['product_id']) {

      }
    }

    // Vignettes
    $imgs_path = yks::$get->config->shop['imgs_url_mask']?yks::$get->config->shop['imgs_url_mask']:"/imgs/".SITE_BASE."/products/%s";
    foreach($products as $product)
      $product->product_img = sprintf($imgs_path, $product['product_id']);

    // Heritage
    self::product_variations($products);

    if(!$related_products)
      $products = array_intersect_key($products, array_flip($head_products_list));

    return $products;
  }


  private static function product_variations($products) {

{'fraction_non_alphanumeric': 0.15220313666915608, 'fraction_numerical': 0.0, 'mean_word_length': 4.80745880312229, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2988133', 'n_tokens_mistral': 2133, 'n_tokens_neox': 2096, 'n_words': 311}