Developer notes
| Table | Content |
|---|---|
?:kv_nyp_rules |
One rule per product (object_type P) or category (C): mode Y/N, basis A (amount) / P (percent of the regular price), min_amount, suggested, max_amount, b1-b3, hide_price, company_id, admin_set (Y = saved by an administrator). |
?:kv_nyp_rule_descriptions |
Per language: label, help, b1_label-b3_label. |
?:kv_nyp_sales |
One row per order line with a buyer-set price (report): order, line, product, company, quantity, price (primary currency), typed amount and currency, minimum, suggested, button (0 = own amount). Multi-Vendor parent orders are skipped. |
The amount a buyer chose travels in the cart line’s extra.kv_nyp (price in the primary currency, typed amount, currency, button, minimum, maximum, suggested, rule id) and from there into ?:order_details.extra, so every order keeps it even without the add-on.
Hooks used (identical in 4.17.2 and 4.21.2)
Section titled “Hooks used (identical in 4.17.2 and 4.21.2)”PHP: pre_add_to_cart (validate the posted product_data[<id>][kv_nyp_price] / [kv_nyp_button], store the marker; a marker sent by the browser is always removed), generate_cart_id (separate lines per price), add_product_to_cart_get_price (zero-priced products), exclude_products_from_calculation (re-validate every line on every calculation, set stored_price = Y and the price, or remove the line), calculate_cart_items and get_cart_product_data_post (promotions policy, cart note data), place_order, get_order_info, delete_order (report rows, order line text), update_product_post, update_category_post, clone_product, delete_product_post, delete_category_post (rules).
Templates (storefront, Responsive and every theme that includes its common/product_data.tpl, Nova included): products:qty (pre, amount picker inside the add-to-cart form, own cm-reload wrapper so option changes reload it), products:prices_block (override, only for “hide the regular price”; empty output otherwise), products:product_labels (post, list label), checkout:product_info (post, cart note). Admin: products:tabs_content, categories:tabs_content (post, editor tabs).
Validation and rounding
Section titled “Validation and rounding”Calc::amounts()computes the effective amounts of a rule (primary currency): fixed basis with option modifiers throughfn_apply_options_modifiers(), percent basis fromfn_get_product_price()+ modifiers; minimum rounded up (at least one minor unit), maximum rounded down, suggested and buttons rounded half up and kept only inside the range.Calc::check()validates a typed amount in the visitor’s currency: parsing (Money::parse()accepts “12”, “12.50”, “12,50”, “1,234.56”, “1.234,56”, symbols and spaces; refuses negatives, letters and absurd values), rounding to the currency’s decimals, comparison with the converted minimum (rounded up) / maximum (rounded down), conversion to the primary currency (amount * coefficient) and snapping onto the limit when the conversion rounding lands a fraction outside.Calc::fits()is the cart recalculation check.
Full page cache and block cache
Section titled “Full page cache and block cache”The amount picker, the price label and the list label depend only on the product, the options, the currency and the customer-group price, never on the visitor’s session; the amount is validated on the server. Product blocks get kv_nyp_rules and kv_nyp_rule_descriptions as cache update handlers and a cache key part with the licence and settings state (schemas/block_manager/*.post.php).
Templates in your own theme
Section titled “Templates in your own theme”If your theme overrides common/product_data.tpl without the products:qty hook, add {hook name="products:qty"}{/hook} inside the add-to-cart form, or include addons/kv_name_your_price/hooks/products/qty.pre.tpl there. The widget needs the variables $product, $obj_id, $obj_prefix and $details_page.
Public helpers
Section titled “Public helpers”fn_kv_name_your_price_widget(array $product): widget data or null.\Tygh\Addons\KvNameYourPrice\Rules::effective($product_id, $options, $auth): effective amounts or null.\Tygh\Addons\KvNameYourPrice\Report::build($filter, $company_id)/::csv(...).
Upgrades
Section titled “Upgrades”The add-on ships Upgrade\Synchronizer: after files are replaced (upload over the installed add-on, Upgrade Center, FTP) the first admin page creates missing tables, columns and settings and updates the version. Uninstall keeps the data unless “Delete all data on uninstall” is on (Retention).