Adapt Your Add-ons and Themes to CS-Cart 4.9.1

Common Changes

  1. Profile types have been added. For now, two types are available:

    • U—user profile (administrator, customer, vendor’s administrator)
    • S—seller (vendor) profile

    Profile type selector has been added to the profile fields management page (Administration → Profile fields). The sidebar with the selector shows up if more than one profile type are available.

    The Vendor information section on profile fields management page determines what fields will be available on the Become a seller form.

  2. The support of the fax field has been removed from the code and templates. For existing installations, the fax field in the cscart_companies table will remain unchanged, but new installations won’t have it.

  3. It is no longer possible to change the type of a user group type after the user group has been created, or to assign a user group to the wrong type of users.

  4. A vendor’s administrator with a user group assigned is no longer treated as restricted administrator.

  5. A new directive show_on_locations is now available for the blocks schema. That directive allows you to specify the locations the block can be added to. This restriction works when you try to add a block trough interface, and prevents the block from showing up if it has already been added.

  6. A new setting has been added to the Products tab of the Comments and reviews add-on. That setting allows posting reviews only to those who have bought the product.

  7. The logic of leaving reviews is now slightly different. A user must now be signed in to leave a review. If the user isn’t signed in, an attempt to leave a review will open the sign-in form. Both the sign-in form and new form for writing a review now are being fetched via AJAX.

  8. The interface for closing storefronts has changed:

    • In CS-Cart, a store can now be closed on the list of stores or on the store editing page. The top menu bar changes its color depending on the status of the currently selected store. In the “All stores” mode, a lock icon will appear; it will look different, depending on what number of storefronts is closed.
    • In Multi-Vendor, the color of top menu will change depending on storefront status, and the lock icon will lead to Settings → General where the storefront can be reopened.
  9. The Vendor plans: Commissions by category add-on has been added. It allows to set order commissions for vendors depending on the categories to which the ordered products belong.

  10. A new data attribute caScrollToElmOffset has been added. This attribute allows you to offset the scroll when a page is automatically scrolled to some specific element. This comes useful when there is a custom top sticky menu that runs over the element after automatic scrolling.

    Add the attribute to the <body> tag with a value in pixels, for example:

    <body data-ca-scroll-to-elm-offset="120">
    

    You can use the attribute on the storefront and in the administration panel (we now use it there too).

Locks

A component for locks based on symfony/lock has been implemented; it allows to guarantee exclusive access to shared resources.

To create a lock, use Tygh::$app['lock.factory'].

Usage example:

$lock = Tygh::$app['lock.factory']->createLock('pdf-invoice-generation');

if ($lock->acquire()) {
   // The resource "pdf-invoice-generation" is locked.
   // You can compute and generate invoice safely here.

   $lock->release();
}

An exclusive lock was added for cache generation in the block manager, styles and JS compilation to prevent a race condition.

To disable locks, use the dummy provider:

$config['lock_backend'] = 'dummy';

Deprecated Templates

  • design/backend/templates/views/orders/components/payments/business_check.tpl
  • design/backend/templates/views/orders/components/payments/check.tpl
  • design/backend/templates/views/orders/components/payments/fax.tpl
  • design/themes/basic/templates/views/orders/components/payments/business_check.tpl
  • design/themes/basic/templates/views/orders/components/payments/check.tpl
  • design/themes/basic/templates/views/orders/components/payments/fax.tpl
  • design/themes/responsive/templates/views/orders/components/payments/business_check.tpl
  • design/themes/repsonsive/templates/views/orders/components/payments/check.tpl
  • design/themes/responsive/templates/views/orders/components/payments/fax.tpl

Hook Changes

New Hooks

  1. This hook allows you to modify profile fields after fetching them:

    fn_set_hook('get_profile_fields_post', $location, $_auth, $lang_code, $params, $profile_fields, $sections);
    
  2. This hook allows you to modify user group availability for the user after the main check has been performed:

    fn_set_hook('check_usergroup_available_for_user_post', $user_id, $usergroup_id, $result);
    
  3. This hook allows you to modify privileges after fetching them:

    fn_set_hook('get_privileges_post', $usergroup, $privileges);
    
  4. This hook allows to modify the availability of user group privileges after the main check:

    fn_set_hook('check_can_usergroup_have_privileges_post', $usergroup, $result);
    
  5. This hook allows you to extend the available user group types:

    fn_set_hook('usergroup_types_get_list', $types);
    
  6. This hook allows you to extend the mapping of user types to user group types:

    fn_set_hook('usergroup_types_get_map_user_type', $map);
    
  7. This hook is executed right after the user authentication data is obtained from API request headers. The hook allows you to modify the data that is used to identify the user who accesses the API:

    fn_set_hook('api_get_user_data', $this, $auth);
    
  8. This hook allows you to skip clearing the cart when the catalog mode is enabled:

    fn_set_hook("catalog_mode_pre_add_to_cart", $product_data, $cart, $auth, $update, $can_delete);
    
  9. This hook allows you to influence the process of updating the prices of a product:

    fn_set_hook('update_product_prices', $product_id, $_product_data, $company_id, $skip_price_delete, $table_name, $condition);
    
  10. This hook allows you to change pagination data:

    fn_set_hook('generate_pagination_pre', $params, $area, $deviation);
    

Changed Hooks

  1. // Old:
    fn_set_hook('update_product_amount_pre', $product_id, $amount, $product_options, $sign, $tracking, $current_amount, $product_code);
    
    // New:
    fn_set_hook('update_product_amount_pre', $product_id, $amount, $product_options, $sign, $tracking, $current_amount, $product_code, $notify);
    
  2. // Old:
    fn_set_hook('update_product_amount', $new_amount, $product_id, $cart_id, $tracking);
    
    // New:
    fn_set_hook('update_product_amount', $new_amount, $product_id, $cart_id, $tracking, $notify);
    
  3. // Old:
    fn_set_hook('update_product_amount_post', $product_id, $amount, $product_options, $sign, $tracking, $current_amount, $new_amount, $product_code);
    
    // New:
    fn_set_hook('update_product_amount_post', $product_id, $amount, $product_options, $sign, $tracking, $current_amount, $new_amount, $product_code, $notify);
    

Deprecated Hooks

fn_set_hook('profile_fields_areas', $areas); is now deprecated; use the profile_fields schema instead.

Core Functions

New Functions

  1. Arrange product categories sequentially in the database:

    fn_sort_product_categories($product_id, array $category_ids)
    
  2. Check if the user group with the provided ID can be assigned to the user:

    fn_check_usergroup_available_for_user($user_id, $usergroup_id)
    
  3. Fetch user group privileges:

    fn_get_usergroup_privileges(array $usergroup)
    
  4. Сheck if the provided user group can have privileges:

    fn_check_can_usergroup_have_privileges(array $usergroup)
    
  5. Fetch all available user groups by user type:

    fn_get_available_usergroups($user_type)
    
  6. Fetch access key for a specific closed storefront:

    fn_ult_get_storefront_access_key($company_id)
    
  7. Fetch the status of the specific storefront:

    fn_ult_get_storefront_status($company_id)
    
  8. Open the specific storefront:

    fn_ult_open_storefront($company_id)
    
  9. Close the specific storefront:

    fn_ult_close_storefront($company_id)
    
  10. Determine whether or not shipping cost must be recalculated at the current checkout step:

    fn_checkout_step_needs_shipping_calculation($cart, $completed_steps)
    
  11. Determine whether or not user data was changed in the cart:

    fn_is_cart_user_data_changed(array &$cart, array $auth)
    
  12. Fetch the offer type:

    \Tygh\Ym\Offers::getOfferType($product)
    
  13. Fetch the map language:

    fn_rus_pickup_get_map_language($lang_code)
    
  14. Handle the preset file upload process:

    \Tygh\Addons\AdvancedImport\Readers\Factory::uploadPresetFile(array $preset, $company_id = null)
    

Changed Functions

  1. // Old:
    function fn_set_store_mode($store_mode, $company_id = null)
    
    // New:
    function fn_set_store_mode($store_mode, $company_id = null, $clear_cache = true)
    
  2. // Old:
    function fn_update_product_amount($product_id, $amount, $product_options, $sign)
    
    // New:
    function fn_update_product_amount($product_id, $amount, $product_options, $sign, $notify = true)
    
  3. \Tygh\Registry::loadFromCache now retrieves a value from cache with a specified key.

  4. \Tygh\BlockManager\RenderManager::registerBlockCacheIfNeeded now returns an array with the caching parameter, if successful.

  5. fn_get_usergroups now returns user groups only of registered types. To register a user group type, use the usergroup_types_get_list hook.

  6. fn_define_usergroups now defines user groups only of registered types and associated with user type. To associate a user group type with user type, use the usergroup_types_get_map_user_type hook.

New Classes

Tygh\Enum\Addons\Pickup\MapLanguage—enumeration of map languages.