yf_shop__basket_api user module

Abstraction layer on basket inner representation with basic manipulation methods: get/set/del/clean...

Fileplugins/shop/modules/shop/yf_shop__basket_api.class.php
Usemodule('shop__basket_api'), URL ?object=shop__basket_api

Public properties

A site sets them in its config with $PROJECT_CONF['shop__basket_api']['NAME'] = ...;

PropertyDefaultDescription
$storage_name 'shop_basket_storage'

Public methods 7

clean

public function clean()
    public function clean()
    {
        $storage_name = $this->_storage_name();
        $_SESSION[$storage_name] = [];
        return true;
    }

del

public function del($k)
    public function del($k)
    {
        $storage_name = $this->_storage_name();
        unset($_SESSION[$storage_name][$k]);
        return true;
    }

get

public function get($k, $k2 = false)
    public function get($k, $k2 = false)
    {
        $storage_name = $this->_storage_name();
        if ( ! empty($k2)) {
            return $_SESSION[$storage_name][$k][$k2] ?? null;
        }
        return $_SESSION[$storage_name][$k] ?? null;
    }

get_all

public function get_all()
    public function get_all()
    {
        $storage_name = $this->_storage_name();
        return $_SESSION[$storage_name];
    }

set

public function set($k, $v)
    public function set($k, $v)
    {
        $storage_name = $this->_storage_name();
        $_SESSION[$storage_name][$k] = $v;
        return true;
    }

Methods starting with _ hooks and helpers; not routable as page actions

_basket_api

public function _basket_api()

API Wrapper, allowing to chain itself.

    public function _basket_api()
    {
        return $this;
    }

_storage_name

public function _storage_name()

Storage key in $_SESSION. Baskets saved before the key was used live in $_SESSION[''] and are moved once.

    public function _storage_name()
    {
        if ( ! empty($_SESSION['']) && is_array($_SESSION['']) && empty($_SESSION[$this->storage_name])) {
            $_SESSION[$this->storage_name] = $_SESSION[''];
            unset($_SESSION['']);
        }
        return $this->storage_name;
    }