# fluent-cart/1.6.4/app/Modules/Data/ProductDataSetup.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.6.4. 64 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Modules/Data/ProductDataSetup.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.4/raw/app/Modules/Data/ProductDataSetup.php
- Modified: 2025-10-14T16:36:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Modules/Data/ProductDataSetup.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Modules\Data;

use FluentCart\App\CPT\FluentProducts;
use FluentCart\App\Models\Product;

class ProductDataSetup
{

    protected static $productsCache = [];

    public function boot()
    {
        static $booted = false;

        if ($booted) {
            return;
        }

        add_action('the_post', [$this, 'maybeSetupProductData'], 1);
        $booted = true;
    }

    public function maybeSetupProductData($post)
    {
        unset($GLOBALS['fct_product']);

        if (is_int($post)) {
            $post = get_post($post);
        }

        if (empty($post->post_type) || $post->post_type !== FluentProducts::CPT_NAME) {
            return $post;
        }

        $GLOBALS['fct_product'] = self::getProductModel($post->ID);

        return $post;
    }

    public static function getProductModel($postId)
    {
        if (isset(self::$productsCache[$postId])) {
            return self::$productsCache[$postId];
        }

        $product = Product::query()->find($postId);

        if ($product) {
            self::$productsCache[$postId] = $product;
        }

        return $product;
    }

    public static function setProductsCache($products)
    {
        foreach ($products as $product) {
            self::$productsCache[$product->ID] = $product;
        }
    }
}

```
