yf_shop__get_select_attributes user module

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

Public properties

PropertyDefaultDescription
None declared in this class.

Public methods 1

None without a leading underscore.

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

public function _get_select_attributes($atts = [])
    public function _get_select_attributes($atts = [])
    {
        $selected = null;
        if (empty($atts)) {
            return [];
        }
        // Group by attribute name
        $_atts_by_name = [];
        $_atts_products_ids = null;
        foreach ((array) $atts as $_info) {
            $_atts_products_ids[$_info['name']] = $_info['product_id'];
            $_price_text = ' (' . ($_info['price'] < 0 ? '-' : '+') . module('shop')->_format_price(abs($_info['price'])) . ')';
            $_atts_by_name[$_info['name']][$_info['value']] = $_info['value'] . ($_info['price'] ? $_price_text : '');
        }
        $result = [];
        foreach ((array) $_atts_by_name as $_name => $_info) {
            $_product_id = $_atts_products_ids[$_name];
            $_box = '';
            $_box_name = 'atts[' . (int) $_product_id . '][' . $_name . ']';
            if (count((array) $_info) > 1) {
                $_box = common()->select_box($_box_name, $_info, null, false, 2, '', false);
            } else {
                $_box = current($_info) . "\n<input type=\"hidden\" name=\"" . $_box_name . '" value="' . _prepare_html(current($_info)) . '" />';
            }
            $result[$_name] = [
                'name' => _prepare_html($_name),
                'box' => $_box,
            ];
        }
        return $result;
    }