<?php
 
 /**
 * =============================================================================
 * @package         Blue Raven (Free Version)
 * @Plugin URI      https://enterrahost.com/plugins/blue-raven
 * 
 * @Author          EnterraHost
 * @Author URI      https://enterrahost.com
 * @License         GPL-2.0-or-later
 *  
 * @Copyright       (c) 2025 EnterraHost
 * @Contents        Load A Product ( Helper Function )
 *
 * =============================================================================
 * 
 * || INDEX:
 * ||   - LOAD ONE PRODUCT
 * ||   - FETCH ATTRIBITES BLOCK 
 * || 
 * =============================================================================
 */

if ( ! defined( 'ABSPATH' ) ) exit; 

/*
============================================================
    LOAD ONE PRODUCT
============================================================
*/

function BlueRaven_fetchAProduct($product_id) {
    global $wpdb;

    if (!is_numeric($product_id)) return null;

    $table = $wpdb->prefix . 'BlueRavenProducts';
    return $wpdb->get_row($wpdb->prepare("SELECT * FROM $table WHERE id = %d", $product_id),ARRAY_A);
}

/*
============================================================
    FETCH ATTRIBITES BLOCK 
============================================================
*/

function BlueRaven_fetchAttributesBlock($attributes) {
    $decoded = json_decode($attributes, true);
    ob_start();
    foreach ($decoded as $index => $attribute) {include BLUERAVEN_PLUGIN_DIR . 'templates/blocks/block-attribute-row.php';}
    return ob_get_clean();
}
