# fluent-cart/1.6.4/api/Contracts/CanEnqueue.php

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

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/api/Contracts/CanEnqueue.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.4/raw/api/Contracts/CanEnqueue.php
- Modified: 2026-03-13T16:10:00+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/api/Contracts/CanEnqueue.php#L10-L20`.

```php
<?php

namespace FluentCart\Api\Contracts;

use FluentCart\App\Helpers\Helper;
use FluentCart\App\Vite;
use FluentCart\Framework\Support\Str;

trait CanEnqueue
{
    protected ?string $slugPrefix = null;
    protected ?string $localizationKey = null;

    protected $isStylesLoaded = false;
    protected $isScriptsLoaded = false;


    protected function getScriptName(): string
    {
        return $this->generateEnqueueSlug() . '_js';
    }

    public function getScripts(): array
    {
        return [];
    }

    public function enqueueScripts()
    {
        if ($this->isScriptsLoaded) {
            return;
        }

        $this->isScriptsLoaded = true;

        $localizeData = $this->localizeData();
        $localizeData['fluentCartRestVars'] = [
            'rest'    => Helper::getRestInfo(),
            'ajaxurl' => admin_url('admin-ajax.php')
        ];

        $this->enqueue_scripts($localizeData);


    }

    public function enqueue_scripts($localizeData = []): void
    {
        Vite::enqueueAllScripts(
            $this->getScripts(),
            $this->getScriptName(),
            $localizeData
        );
    }

    public function getStyles(): array
    {
        return [];
    }

    protected function getStyleName(): string
    {
        return $this->generateEnqueueSlug() . '_css';
    }

    public function enqueueStyles()
    {
        if ($this->isStylesLoaded) {
            return;
        }

        $this->isStylesLoaded = true;

        $this->enqueue_styles();
    }

    public function enqueue_styles(): void
    {
        Vite::enqueueAllStyles(
            $this->getStyles(),
            $this->getStyleName()
        );
    }

    abstract protected function generateEnqueueSlug(): string;

    protected function getLocalizationKey(): string
    {
        return $this->localizationKey ??
            $this->generateEnqueueSlug() . '_data';
    }


    public function localizeData(): array
    {
        return [];
    }

    public function enqueueAssets()
    {
        $this->enqueueScripts();
        $this->enqueueStyles();
        return $this;
    }
}

```
