Skip to content

Latest commit

 

History

History
2531 lines (1288 loc) · 60 KB

class.CartRuleCore.md

File metadata and controls

2531 lines (1288 loc) · 60 KB

Class CartRuleCore

Contents

Constants

Properties

Methods

Constants

BO_ORDER_CODE_PREFIX

const BO_ORDER_CODE_PREFIX = 'BO_ORDER_'

FILTER_ACTION_ALL

const FILTER_ACTION_ALL = 1

FILTER_ACTION_ALL_NOCAP

const FILTER_ACTION_ALL_NOCAP = 5

FILTER_ACTION_GIFT

const FILTER_ACTION_GIFT = 4

FILTER_ACTION_REDUCTION

const FILTER_ACTION_REDUCTION = 3

FILTER_ACTION_SHIPPING

const FILTER_ACTION_SHIPPING = 2

Properties

$active

public mixed $active = 1

$carrier_restriction

public mixed $carrier_restriction

$cart_rule_restriction

public mixed $cart_rule_restriction

$code

public mixed $code

$country_restriction

public mixed $country_restriction

$date_add

public mixed $date_add

$date_from

public mixed $date_from

$date_to

public mixed $date_to

$date_upd

public mixed $date_upd

$definition

public mixed $definition = array('table' => 'cart_rule', 'primary' => 'id_cart_rule', 'multilang' => true, 'fields' => array('id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'date_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true), 'date_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true), 'description' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 65534), 'quantity' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'quantity_per_user' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'priority' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'partial_use' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'code' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 254), 'minimum_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'), 'minimum_amount_tax' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'minimum_amount_currency' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'minimum_amount_shipping' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'country_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'carrier_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'group_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'cart_rule_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'product_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'shop_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'free_shipping' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'reduction_percent' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPercentage'), 'reduction_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'), 'reduction_tax' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'reduction_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'reduction_product' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'gift_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'gift_product_attribute' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'highlight' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 254)))

$description

public mixed $description

$free_shipping

public mixed $free_shipping

$gift_product

public mixed $gift_product

$gift_product_attribute

public mixed $gift_product_attribute

$group_restriction

public mixed $group_restriction

$highlight

public mixed $highlight

$id

public mixed $id

$id_customer

public mixed $id_customer

$minimum_amount

public mixed $minimum_amount

$minimum_amount_currency

public mixed $minimum_amount_currency

$minimum_amount_shipping

public mixed $minimum_amount_shipping

$minimum_amount_tax

public mixed $minimum_amount_tax

$name

public mixed $name

$only_one_gift

protected mixed $only_one_gift = array()

$partial_use

public mixed $partial_use = 1

$priority

public mixed $priority = 1

$product_restriction

public mixed $product_restriction

$quantity

public mixed $quantity = 1

$quantity_per_user

public mixed $quantity_per_user = 1

$reduction_amount

public mixed $reduction_amount

$reduction_currency

public mixed $reduction_currency

$reduction_percent

public mixed $reduction_percent

$reduction_product

public mixed $reduction_product

$reduction_tax

public mixed $reduction_tax

$shop_restriction

public mixed $shop_restriction

$cache_objects

protected boolean $cache_objects = true

$db

protected \Db $db = false

$def

protected array $def

$fieldsRequired

protected array $fieldsRequired = array()

$fieldsRequiredDatabase

protected array $fieldsRequiredDatabase = null

$fieldsRequiredLang

protected array $fieldsRequiredLang = array()

$fieldsSize

protected array $fieldsSize = array()

$fieldsSizeLang

protected array $fieldsSizeLang = array()

$fieldsValidate

protected array $fieldsValidate = array()

$fieldsValidateLang

protected array $fieldsValidateLang = array()

$force_id

public boolean $force_id = false

$get_shop_from_context

protected boolean $get_shop_from_context = true

$id_lang

protected integer $id_lang = null

$id_shop

protected integer $id_shop = null

$id_shop_list

public array $id_shop_list = null

$identifier

protected string $identifier

$image_dir

protected string $image_dir = null

$image_format

protected String $image_format = 'jpg'

$loaded_classes

protected array $loaded_classes = array()

Holds compiled definitions of each ObjectModel class.

Values are assigned during object initialization.

$table

protected string $table

$tables

protected array $tables = array()

$update_fields

protected array $update_fields = null

$webserviceParameters

protected array $webserviceParameters = array()

Methods

__construct

mixed ObjectModelCore::__construct(integer|null $id, integer|null $id_lang, integer|null $id_shop)

Builds the object

Arguments

  • $id integer|null - If specified, loads and existing object from DB (optional).
  • $id_lang integer|null - Required if object is multilingual (optional).
  • $id_shop integer|null - ID shop for objects with multishop tables.

add

mixed CartRuleCore::add($autodate, $null_values)

Arguments

  • $autodate mixed
  • $null_values mixed

addFieldsRequiredDatabase

boolean ObjectModelCore::addFieldsRequiredDatabase(array $fields)

Sets required field for this class in the database.

Arguments

  • $fields array

array_uintersect

mixed CartRuleCore::array_uintersect($array1, $array2)

Arguments

  • $array1 mixed
  • $array2 mixed

array_uintersect_compare

mixed CartRuleCore::array_uintersect_compare($a, $b)

Arguments

  • $a mixed
  • $b mixed

associateTo

boolean|void ObjectModelCore::associateTo(integer|array $id_shops)

This function associate an item to its context

Arguments

  • $id_shops integer|array

autoAddToCart

mixed CartRuleCore::autoAddToCart(\Context|null $context)

Arguments

autoRemoveFromCart

mixed CartRuleCore::autoRemoveFromCart($context)

Arguments

  • $context mixed

cacheFieldsRequiredDatabase

mixed ObjectModelCore::cacheFieldsRequiredDatabase(boolean $all)

Caches data about required objects fields in memory

Arguments

  • $all boolean - If true, caches required fields of all object classes.

cartRuleExists

boolean CartRuleCore::cartRuleExists($name)

Arguments

  • $name mixed

checkProductRestrictions

mixed CartRuleCore::checkProductRestrictions(\Context $context, $return_products, $display_error, $already_in_cart)

Arguments

  • $context Context
  • $return_products mixed
  • $display_error mixed
  • $already_in_cart mixed

checkValidity

boolean|mixed|string CartRuleCore::checkValidity(\Context $context, boolean $alreadyInCart, boolean $display_error, $check_carrier)

Check if this cart rule can be applied

Arguments

  • $context Context
  • $alreadyInCart boolean - Check if the voucher is already on the cart
  • $display_error boolean - Display error
  • $check_carrier mixed

cleanCache

mixed CartRuleCore::cleanCache()

Make sure caches are empty Must be called before calling multiple time getContextualValue()

cleanProductRuleIntegrity

mixed CartRuleCore::cleanProductRuleIntegrity($type, $list)

Arguments

  • $type mixed
  • $list mixed

clearCache

mixed ObjectModelCore::clearCache(boolean $all)

Clears cache entries that have this object's ID.

Arguments

  • $all boolean - If true, clears cache for all objects

copyConditions

mixed CartRuleCore::copyConditions(integer $id_cart_rule_source, integer $id_cart_rule_destination)

Copy conditions from one cart rule to an other

Arguments

  • $id_cart_rule_source integer
  • $id_cart_rule_destination integer

delete

mixed CartRuleCore::delete()

deleteByIdCustomer

boolean CartRuleCore::deleteByIdCustomer($id_customer)

Arguments

  • $id_customer mixed

deleteImage

boolean ObjectModelCore::deleteImage(boolean $force_delete)

Delete images associated with the object

Arguments

  • $force_delete boolean

deleteSelection

boolean ObjectModelCore::deleteSelection(array $ids)

Deletes multiple objects from the database at once

Arguments

  • $ids array - Array of objects IDs.

disableCache

mixed ObjectModelCore::disableCache()

Disables object caching

displayFieldName

string ObjectModelCore::displayFieldName(string $field, string $class, boolean $htmlentities, \Context|null $context)

Returns field name translation

Arguments

  • $field string - Field name
  • $class string - ObjectModel class name
  • $htmlentities boolean - If true, applies htmlentities() to result string
  • $context Context|null - Context object

duplicateObject

\ObjectModel|false ObjectModelCore::duplicateObject()

Takes current object ID, gets its values from database, saves them in a new row and loads newly saved values as a new object.

duplicateShops

boolean|void ObjectModelCore::duplicateShops($id)

Copies shop association data from object with specified ID.

Arguments

  • $id mixed

enableCache

mixed ObjectModelCore::enableCache()

Enables object caching

existsInDatabase

boolean ObjectModelCore::existsInDatabase(integer $id_entity, string $table)

Checks if an object exists in database.

Arguments

  • $id_entity integer
  • $table string

formatFields

array ObjectModelCore::formatFields(integer $type, integer $id_lang)

Formats values of each fields.

Arguments

  • $type integer - FORMAT_COMMON or FORMAT_LANG or FORMAT_SHOP
  • $id_lang integer - If this parameter is given, only take lang fields

formatValue

mixed ObjectModelCore::formatValue(mixed $value, integer $type, boolean $with_quotes, boolean $purify, boolean $allow_null)

Formats a value

Arguments

  • $value mixed
  • $type integer
  • $with_quotes boolean
  • $purify boolean
  • $allow_null boolean

getAssociatedRestrictions

array|boolean CartRuleCore::getAssociatedRestrictions(string $type, boolean $active_only, boolean $i18n, integer $offset, integer $limit, string $search_cart_rule_name)

Arguments

  • $type string
  • $active_only boolean
  • $i18n boolean
  • $offset integer
  • $limit integer
  • $search_cart_rule_name string

getAssociatedShops

array ObjectModelCore::getAssociatedShops()

Gets the list of associated shop IDs

getCartRuleCombinations

array CartRuleCore::getCartRuleCombinations(integer $offset, integer $limit, string $search)

Arguments

  • $offset integer
  • $limit integer
  • $search string

getCartsRuleByCode

array CartRuleCore::getCartsRuleByCode($name, $id_lang, $extended)

Arguments

  • $name mixed
  • $id_lang mixed
  • $extended mixed

getContextualValue

float|integer|string CartRuleCore::getContextualValue(boolean $use_tax, \Context $context, $filter, $package, boolean $use_cache)

The reduction value is POSITIVE

Arguments

  • $use_tax boolean
  • $context Context
  • $filter mixed
  • $package mixed
  • $use_cache boolean - Allow using cache to avoid multiple free gift using multishipping

getCustomerCartRules

array CartRuleCore::getCustomerCartRules($id_lang, $id_customer, boolean $active, boolean $includeGeneric, boolean $inStock, \Cart|null $cart, boolean $free_shipping_only, boolean $highlight_only)

Arguments

  • $id_lang mixed
  • $id_customer mixed
  • $active boolean
  • $includeGeneric boolean
  • $inStock boolean
  • $cart Cart|null
  • $free_shipping_only boolean
  • $highlight_only boolean

getDefinition

array ObjectModelCore::getDefinition(string $class, string|null $field)

Returns object definition

Arguments

  • $class string - Name of object
  • $field string|null - Name of field if we want the definition of one field only

getFieldByLang

mixed ObjectModelCore::getFieldByLang(string $field_name, integer|null $id_lang)

Return the field value for the specified language if the field is multilang, else the field value.

Arguments

  • $field_name string
  • $id_lang integer|null

getFields

array ObjectModelCore::getFields()

Prepare fields for ObjectModel class (add, update) All fields are verified (pSQL, intval, .

..)

getFieldsLang

array ObjectModelCore::getFieldsLang()

Prepare multilang fields

getFieldsRequiredDatabase

array|null ObjectModelCore::getFieldsRequiredDatabase(boolean $all)

Returns an array of required fields

Arguments

  • $all boolean - If true, returns required fields of all object classes.

getFieldsShop

array ObjectModelCore::getFieldsShop()

Prepare fields for multishop Fields are not validated here, we consider they are already validated in getFields() method, this is not the best solution but this is the only one possible for retro compatibility.

getIdByCode

integer|boolean CartRuleCore::getIdByCode(string $code)

Retrieves the id associated to the given code

Arguments

  • $code string

getProductRuleGroups

array CartRuleCore::getProductRuleGroups()

getProductRules

array CartRuleCore::getProductRules($id_product_rule_group)

Arguments

  • $id_product_rule_group mixed

getRepositoryClassName

mixed ObjectModelCore::getRepositoryClassName()

Returns the name of the repository class for this entity.

If unspecified, a generic repository will be used for the entity.

getTranslationsFields

array ObjectModelCore::getTranslationsFields(array $fields_array)

Arguments

  • $fields_array array

getValidationRules

array ObjectModelCore::getValidationRules(string $class)

Returns object validation rules (fields validity)

Arguments

  • $class string - Child class name for static use (optional)

getWebserviceObjectList

array|null ObjectModelCore::getWebserviceObjectList(string $sql_join, string $sql_filter, string $sql_sort, string $sql_limit)

Returns webservice object list.

Arguments

  • $sql_join string
  • $sql_filter string
  • $sql_sort string
  • $sql_limit string

getWebserviceParameters

array ObjectModelCore::getWebserviceParameters(string|null $ws_params_attribute_name)

Returns webservice parameters of this object.

Arguments

  • $ws_params_attribute_name string|null

hasMultishopEntries

boolean ObjectModelCore::hasMultishopEntries()

Checks if there is more than one entry in associated shop table for current object.

hydrate

mixed ObjectModelCore::hydrate(array $data, integer|null $id_lang)

Fill an object with given data. Data must be an array with this syntax: array(objProperty => value, objProperty2 => value, etc.)

Arguments

  • $data array
  • $id_lang integer|null

hydrateCollection

array ObjectModelCore::hydrateCollection(string $class, array $datas, integer|null $id_lang)

Fill (hydrate) a list of objects in order to get a collection of these objects

Arguments

  • $class string - Class of objects to hydrate
  • $datas array - List of data (multi-dimensional array)
  • $id_lang integer|null

isAssociatedToShop

boolean ObjectModelCore::isAssociatedToShop(integer|null $id_shop)

Checks if current object is associated to a shop.

Arguments

  • $id_shop integer|null

isCurrentlyUsed

boolean ObjectModelCore::isCurrentlyUsed(string|null $table, boolean $has_active_column)

Checks if an object type exists in the database.

Arguments

  • $table string|null - Name of table linked to entity
  • $has_active_column boolean - True if the table has an active column

isFeatureActive

boolean CartRuleCore::isFeatureActive()

isLangMultishop

boolean ObjectModelCore::isLangMultishop()

Checks if the object is both multi-language and multi-shop.

isMultiShopField

boolean ObjectModelCore::isMultiShopField(string $field)

Checks if a field is a multi-shop field.

Arguments

  • $field string

isMultishop

boolean ObjectModelCore::isMultishop()

Checks if object is multi-shop object.

makeTranslationFields

mixed ObjectModelCore::makeTranslationFields(array $fields, array $fields_array, integer $id_language)

Arguments

  • $fields array
  • $fields_array array
  • $id_language integer

save

boolean ObjectModelCore::save(boolean $null_values, boolean $auto_date)

Saves current object to database (add or update)

Arguments

  • $null_values boolean
  • $auto_date boolean

setDefinitionRetrocompatibility

mixed ObjectModelCore::setDefinitionRetrocompatibility()

Retrocompatibility for classes without $definition static

setFieldsToUpdate

mixed ObjectModelCore::setFieldsToUpdate(array $fields)

Set a list of specific fields to update array(field1 => true, field2 => false, langfield1 => array(1 => true, 2 => false))

Arguments

  • $fields array

toggleStatus

boolean ObjectModelCore::toggleStatus()

Toggles object status in database

update

mixed CartRuleCore::update($null_values)

Arguments

  • $null_values mixed

updateMultishopTable

boolean ObjectModelCore::updateMultishopTable(string $classname, array $data, string $where, string $specific_where)

Updates a table and splits the common datas and the shop datas.

Arguments

  • $classname string
  • $data array
  • $where string
  • $specific_where string - Only executed for common table

usedByCustomer

boolean CartRuleCore::usedByCustomer($id_customer)

Arguments

  • $id_customer mixed

validateControler

array ObjectModelCore::validateControler(boolean $htmlentities)

Arguments

  • $htmlentities boolean

validateController

array ObjectModelCore::validateController(boolean $htmlentities)

Validates submitted values and returns an array of errors, if any.

Arguments

  • $htmlentities boolean - If true, uses htmlentities() for field name translations in errors.

validateField

true|string ObjectModelCore::validateField(string $field, mixed $value, integer|null $id_lang, array $skip, boolean $human_errors)

Validate a single field

Arguments

  • $field string - Field name
  • $value mixed - Field value
  • $id_lang integer|null - Language ID
  • $skip array - Array of fields to skip.
  • $human_errors boolean - If true, uses more descriptive, translatable error strings.

validateFields

boolean|string ObjectModelCore::validateFields(boolean $die, boolean $error_return)

Checks if object field values are valid before database interaction

Arguments

  • $die boolean
  • $error_return boolean

validateFieldsLang

boolean|string ObjectModelCore::validateFieldsLang(boolean $die, boolean $error_return)

Checks if multilingual object field values are valid before database interaction.

Arguments

  • $die boolean
  • $error_return boolean

validateFieldsRequiredDatabase

array ObjectModelCore::validateFieldsRequiredDatabase(boolean $htmlentities)

Validate required fields.

Arguments

  • $htmlentities boolean