Skip to content

Latest commit

 

History

History
2068 lines (1081 loc) · 51.3 KB

class.WarehouseCore.md

File metadata and controls

2068 lines (1081 loc) · 51.3 KB

Class WarehouseCore

Holds Stock

Contents

Properties

Methods

Properties

$definition

public mixed $definition = array('table' => 'warehouse', 'primary' => 'id_warehouse', 'fields' => array('id_address' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'reference' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => true, 'size' => 45), 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => true, 'size' => 45), 'id_employee' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'management_type' => array('type' => self::TYPE_STRING, 'validate' => 'isStockManagement', 'required' => true), 'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'deleted' => array('type' => self::TYPE_BOOL)))

$deleted

public boolean $deleted

$id

public integer $id

$id_address

public integer $id_address

$id_currency

public integer $id_currency

$id_employee

public integer $id_employee

$management_type

public string $management_type

Describes the way a Warehouse is managed

$name

public string $name

$reference

public string $reference

$webserviceParameters

protected mixed $webserviceParameters = array('fields' => array('id_address' => array('xlink_resource' => 'addresses'), 'id_employee' => array('xlink_resource' => 'employees'), 'id_currency' => array('xlink_resource' => 'currencies'), 'valuation' => array('getter' => 'getWsStockValue', 'setter' => false), 'deleted' => array()), 'associations' => array('stocks' => array('resource' => 'stock', 'fields' => array('id' => array())), 'carriers' => array('resource' => 'carrier', 'fields' => array('id' => array())), 'shops' => array('resource' => 'shop', 'fields' => array('id' => array(), 'name' => array()))))

$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

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

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

Adds current object to the database

Arguments

  • $auto_date boolean
  • $null_values boolean

addFieldsRequiredDatabase

boolean ObjectModelCore::addFieldsRequiredDatabase(array $fields)

Sets required field for this class in the database.

Arguments

  • $fields array

associateTo

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

This function associate an item to its context

Arguments

  • $id_shops integer|array

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.

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

delete

boolean ObjectModelCore::delete()

Deletes current object from database

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

exists

boolean WarehouseCore::exists(integer $id_warehouse)

Checks if the given warehouse exists

Arguments

  • $id_warehouse integer

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

getAssociatedShops

array ObjectModelCore::getAssociatedShops()

Gets the list of associated shop IDs

getCarriers

array WarehouseCore::getCarriers($return_reference)

Gets the carriers associated to the current warehouse

Arguments

  • $return_reference mixed

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.

getNumberOfProducts

integer WarehouseCore::getNumberOfProducts()

Gets the number of products in the current warehouse

getPackWarehouses

array|boolean WarehouseCore::getPackWarehouses(integer $id_product, $id_shop)

For a given pack, returns the warehouse it can be shipped from

Arguments

  • $id_product integer
  • $id_shop mixed

getProductLocation

string WarehouseCore::getProductLocation(integer $id_product, integer $id_product_attribute, integer $id_warehouse)

For a given {product, product attribute} gets its location in the given warehouse

Arguments

  • $id_product integer - ID of the product
  • $id_product_attribute integer - Use 0 if this product does not have attributes
  • $id_warehouse integer - ID of the warehouse

getProductWarehouseList

array WarehouseCore::getProductWarehouseList(integer $id_product, integer $id_product_attribute, integer $id_shop)

For a given {product, product attribute} gets warehouse list

Arguments

  • $id_product integer - ID of the product
  • $id_product_attribute integer - Optional, uses 0 if this product does not have attributes
  • $id_shop integer - Optional, ID of the shop. Uses the context shop id (@see Context::shop)

getQuantitiesOfProducts

integer WarehouseCore::getQuantitiesOfProducts()

Gets the number of quantities - for all products - in the current warehouse

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.

getShops

array WarehouseCore::getShops()

Gets the shops associated to the current warehouse

getStockValue

integer WarehouseCore::getStockValue()

Gets the value of the stock in the current warehouse

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)

getWarehouseNameById

string WarehouseCore::getWarehouseNameById(integer $id_warehouse)

For a given $id_warehouse, returns its name

Arguments

  • $id_warehouse integer - Warehouse Id

getWarehouses

array WarehouseCore::getWarehouses(boolean $ignore_shop, integer $id_shop)

Gets available warehouses It is possible via ignore_shop and id_shop to filter the list with shop id

Arguments

  • $ignore_shop boolean - Optional, false by default - Allows to get only the warehouses that are associated to one/some shops (@see $id_shop)
  • $id_shop integer - Optional, Context::shop::Id by default - Allows to define a specific shop to filter.

getWarehousesByEmployee

array WarehouseCore::getWarehousesByEmployee(integer $id_employee)

For a given employee, gets the warehouse(s) he/she manages

Arguments

  • $id_employee integer - Manager ID

getWarehousesByProductId

array WarehouseCore::getWarehousesByProductId(integer $id_product, integer $id_product_attribute)

For a given product, returns the warehouses it is stored in

Arguments

  • $id_product integer - Product Id
  • $id_product_attribute integer - Optional, Product Attribute Id - 0 by default (no attribues)

getWarehousesGroupedByShops

array WarehouseCore::getWarehousesGroupedByShops()

Gets warehouses grouped by shops

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

getWsCarriers

array WarehouseCore::getWsCarriers()

Webservice : gets the ids carriers associated to this warehouse

getWsShops

array WarehouseCore::getWsShops()

Webservice : gets the ids shops associated to this warehouse

getWsStockValue

integer WarehouseCore::getWsStockValue()

Webservice : gets the value of the warehouse

getWsStocks

array WarehouseCore::getWsStocks()

Webservice : gets the ids stock associated to this warehouse

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

isEmpty

boolean WarehouseCore::isEmpty()

Checks if a warehouse is empty - i.e. has no stock

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

removeCarrier

mixed WarehouseCore::removeCarrier(integer $id_carrier, integer $id_warehouse)

For a given carrier, removes it from the warehouse/carrier association If $id_warehouse is set, it only removes the carrier for this warehouse

Arguments

  • $id_carrier integer - Id of the carrier to remove
  • $id_warehouse integer - optional Id of the warehouse to filter

resetProductsLocations

mixed WarehouseCore::resetProductsLocations()

Resets all product locations for this warehouse

resetStockAvailable

mixed WarehouseCore::resetStockAvailable()

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

setCarriers

mixed WarehouseCore::setCarriers(array $ids_carriers)

Sets the carriers associated to the current warehouse

Arguments

  • $ids_carriers array

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

setProductLocation

boolean WarehouseCore::setProductLocation(integer $id_product, integer $id_product_attribute, integer $id_warehouse, string $location)

For a given {product, product attribute} sets its location in the given warehouse First, for the given parameters, it cleans the database before updating

Arguments

  • $id_product integer - ID of the product
  • $id_product_attribute integer - Use 0 if this product does not have attributes
  • $id_warehouse integer - ID of the warehouse
  • $location string - Describes the location (no lang id required)

toggleStatus

boolean ObjectModelCore::toggleStatus()

Toggles object status in database

update

boolean ObjectModelCore::update(boolean $null_values)

Updates the current object in the database

Arguments

  • $null_values boolean

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

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