sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
protected function setStateCity($state_id) { $this->data_state = $this->state->get($state_id); if (empty($this->data_state)) { $this->outputHttpStatus(404); } }
Sets an array of state data @param integer $state_id
entailment
protected function setCountryCity($country_code) { $this->data_country = $this->country->get($country_code); if (empty($this->data_country)) { $this->outputHttpStatus(404); } }
Returns an array of country data @param string $country_code
entailment
protected function setPagerListCity() { $options = $this->query_filter; $options['count'] = true; $options['state_id'] = $this->data_state['state_id']; $pager = array( 'query' => $this->query_filter, 'total' => (int) $this->city->getList($options) ); ...
Sets pager @return array
entailment
protected function getListCity() { $conditions = $this->query_filter; $conditions['limit'] = $this->data_limit; $conditions['state_id'] = $this->data_state['state_id']; return (array) $this->city->getList($conditions); }
Returns an array of cities found for the filter conditions @return array
entailment
protected function setBreadcrumbListCity() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'url' => $this->url('admin/settings/country'), 't...
Sets breadcrumbs on the city overview page
entailment
public function editCity($country_code, $state_id, $city_id = null) { $this->setCity($city_id); $this->setStateCity($state_id); $this->setCountryCity($country_code); $this->setTitleEditCity(); $this->setBreadcrumbEditCity(); $this->setData('city', $this->data_city); ...
Displays the city edit page @param string $country_code @param integer $state_id @param null|integer $city_id
entailment
protected function canDeleteCity() { return isset($this->data_city['city_id']) && $this->access('city_delete') && $this->city->canDelete($this->data_city['city_id']); }
Whether the city can be deleted @return bool
entailment
protected function setCity($city_id) { $this->data_city = array(); if (is_numeric($city_id)) { $this->data_city = $this->city->get($city_id); if (empty($this->data_city)) { $this->outputHttpStatus(404); } } }
Sets an array of city data @param integer $city_id
entailment
protected function submitEditCity() { if ($this->isPosted('delete')) { $this->deleteCity(); } else if ($this->isPosted('save') && $this->validateEditCity()) { if (isset($this->data_city['city_id'])) { $this->updateCity(); } else { $...
Handles a submitted city
entailment
protected function validateEditCity() { $this->setSubmitted('city'); $this->setSubmittedBool('status'); $this->setSubmitted('update', $this->data_city); $this->setSubmitted('country', $this->data_country['code']); $this->setSubmitted('state_id', $this->data_state['state_id'])...
Validates an array of submitted city data @return bool
entailment
protected function deleteCity() { $this->controlAccess('city_delete'); if ($this->city->delete($this->data_city['city_id'])) { $url = "admin/settings/cities/{$this->data_country['code']}/{$this->data_state['state_id']}"; $this->redirect($url, $this->text('City has been delet...
Deletes a city
entailment
protected function updateCity() { $this->controlAccess('city_edit'); if ($this->city->update($this->data_city['city_id'], $this->getSubmitted())) { $url = "admin/settings/cities/{$this->data_country['code']}/{$this->data_state['state_id']}"; $this->redirect($url, $this->text...
Updates a city
entailment
protected function addCity() { $this->controlAccess('city_add'); if ($this->city->add($this->getSubmitted())) { $url = "admin/settings/cities/{$this->data_country['code']}/{$this->data_state['state_id']}"; $this->redirect($url, $this->text('City has been added'), 'success');...
Adds a new city
entailment
protected function setTitleEditCity() { if (isset($this->data_city['city_id'])) { $title = $this->text('Edit %name', array('%name' => $this->data_city['name'])); } else { $title = $this->text('Add city'); } $this->setTitle($title); }
Sets page title on the city edit page
entailment
protected function setBreadcrumbEditCity() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'url' => $this->url('admin/settings/country'), 't...
Sets breadcrumbs on the city edit page
entailment
public function getList(array $options = array()) { $result = null; $this->hook->attach('product.class.list.before', $options, $result, $this); if (isset($result)) { return $result; } $sql = 'SELECT pc.*'; if (!empty($options['count'])) { $s...
Returns an array of product classes or counts them @param array $options @return array|integer
entailment
public function add(array $data) { $result = null; $this->hook->attach('product.class.add.before', $data, $result, $this); if (isset($result)) { return (int) $result; } $result = $this->db->insert('product_class', $data); $this->hook->attach('product.cla...
Adds a product class @param array $data @return integer
entailment
public function canDelete($product_class_id) { $sql = 'SELECT product_id FROM product WHERE product_class_id=?'; $result = $this->db->fetchColumn($sql, array($product_class_id)); return empty($result); }
Whether the product class can be deleted @param integer $product_class_id @return boolean
entailment
public function update($product_class_id, array $data) { $result = null; $this->hook->attach('product.class.update.before', $product_class_id, $data, $result, $this); if (isset($result)) { return (bool) $result; } $conditions = array('product_class_id' => $produ...
Updates a product class @param integer $product_class_id @param array $data @return boolean
entailment
public function getFields($product_class_id) { $result = &gplcart_static("product.class.fields.$product_class_id"); if (isset($result)) { return $result; } $result = array(); $fields = $this->field->getList(); $ops = array( 'product_class_id...
Returns an array of fields for a given product class @param integer $product_class_id @return array
entailment
public function getList($prodict_id) { $result = null; $this->hook->attach('product.field.list.before', $prodict_id, $result, $this); if (isset($result)) { return $result; } $sql = 'SELECT * FROM product_field WHERE product_id=?'; $fields = $this->db->fe...
Returns an array of fields for a given product @param integer $prodict_id @return array
entailment
public function request($url, $options = array()) { $result = null; $this->hook->attach('http.request.before', $url, $options, $result, $this); if (isset($result)) { return $result; } $result = $this->socket->request($url, $options); $this->hook->attach(...
Perform an HTTP request @param string $url @param array $options @return mixed
entailment
public function getList(array $options = array()) { $options += array( 'enabled' => false, 'in_database' => false ); $currencies = &gplcart_static(gplcart_array_hash(array('currency.list' => $options))); if (isset($currencies)) { return $currenci...
Returns an array of currencies @param array $options @return array
entailment
public function add(array $data) { $result = null; $this->hook->attach('currency.add.before', $data, $result, $this); if (isset($result)) { return (bool) $result; } $data['modified'] = GC_TIME; $data['code'] = strtoupper($data['code']); if (!emp...
Adds a currency @param array $data @return boolean
entailment
public function update($code, array $data) { $result = null; $this->hook->attach('currency.update.before', $code, $data, $result, $this); if (isset($result)) { return (bool) $result; } $existing = $this->getList(); if (empty($existing[$code])) { ...
Updates a currency @param string $code @param array $data @return boolean
entailment
public function delete($code, $check = true) { $result = null; $this->hook->attach('currency.delete.before', $code, $check, $result, $this); if (isset($result)) { return (bool) $result; } if ($check && !$this->canDelete($code)) { return false; ...
Deletes a currency @param string $code @param bool $check @return boolean
entailment
public function canDelete($code) { $code = strtoupper($code); if ($code == $this->getDefault()) { return false; } $currencies = $this->config->select('currencies', array()); if (!isset($currencies[$code])) { return false; } $sql = '...
Whether the currency can be deleted @param string $code @return boolean
entailment
public function convert($amount, $from_currency, $to_currency) { if ($from_currency === $to_currency) { return $amount; // Nothing to convert } $currency = $this->get($from_currency); $target_currency = $this->get($to_currency); $exponent = $target_currency['dec...
Converts currencies @param integer $amount @param string $from_currency @param string $to_currency @return integer
entailment
public function getCode($set = true) { $list = $this->getList(); $code = $this->getFromUrl(); if (empty($code)) { $code = $this->getFromCookie(); } if (empty($list[$code]['status'])) { $code = $this->getDefault(); } if ($set) { ...
Returns the current currency code @param bool $set @return string
entailment
public function setCookie($code) { $lifespan = $this->config->get('currency_cookie_lifespan', 365 * 24 * 60 * 60); $this->request->setCookie('currency', $code, $lifespan); }
Saves a currency code in cookie @param string $code
entailment
public function getIso($code = null) { $data = (array) gplcart_config_get(GC_FILE_CONFIG_CURRENCY); if (isset($code)) { return isset($data[$code]) ? $data[$code] + array('code' => $code) : array(); } return $data; }
Returns an array of currencies or a single currency data if $code is set @param null|string $code @return array|string
entailment
public static function get($id) { $instance = self::getInstance(); //缓存文件不存在 if (!$instance->has($id)) { return false; } $file = $instance->_file($id); $data = $instance->_fileGetContents($file); if ($data['expire'] == 0 || time() < $data['expi...
得到缓存信息 @param string $id @return boolean|array
entailment
public static function set($id, $data, $cacheLife = 0) { $instance = self::getInstance(); $time = time(); $cache = array(); $cache['contents'] = $data; $cache['expire'] = $cacheLife === 0 ? 0 : $time + $cacheLife; $cache['mtime'] = $time; $file = $instance->...
设置一个缓存 @param string $id 缓存id @param array $data 缓存内容 @param int $cacheLife 缓存生命 默认为0无限生命
entailment
public static function delete($id) { $instance = self::getInstance(); if (!$instance->has($id)) { return false; } $file = $instance->_file($id); //删除该缓存 return unlink($file); }
清除一条缓存 @param string cache id @return void
entailment
public static function has($id) { $instance = self::getInstance(); $file = $instance->_file($id); if (!is_file($file)) { return false; } return true; }
判断缓存是否存在 @param string $id cache_id @return boolean true 缓存存在 false 缓存不存在
entailment
protected function _file($id) { $instance = self::getInstance(); $fileNmae = $instance->_idToFileName($id); return self::cacheDir() . $fileNmae; }
通过缓存id得到缓存信息路径 @param string $id @return string 缓存文件路径
entailment
protected function _idToFileName($id) { $instance = self::getInstance(); $prefix = $instance->_options['file_name_prefix']; return $prefix . '---' . $id; }
通过id得到缓存信息存储文件名 @param $id @return string 缓存文件名
entailment
protected function _fileNameToId($fileName) { $instance = self::getInstance(); $prefix = $instance->_options['file_name_prefix']; return preg_replace('/^' . $prefix . '---(.*)$/', '$1', $fileName); }
通过filename得到缓存id @param $id @return string 缓存id
entailment
protected function _filePutContents($file, $contents) { if ($this->_options['mode'] == 1) { $contents = serialize($contents); } else { $time = time(); $contents = "<?php\n" . " // mktime: " . $time . "\n" . " return " . ...
把数据写入文件 @param string $file 文件名称 @param array $contents 数据内容 @return bool
entailment
protected function _fileGetContents($file) { if (!is_file($file)) { return false; } if ($this->_options['mode'] == 1) { $f = @fopen($file, 'r'); @$data = fread($f, filesize($file)); @fclose($f); return unserialize($data); }...
从文件得到数据 @param sring $file @return boolean|array
entailment
public static function setCacheMode($mode = 1) { $instance = self::getInstance(); if ($mode == 1) { $instance->_options['mode'] = 1; } else { $instance->_options['mode'] = 2; } return $instance; }
设置缓存存储类型 @param int $mode @return self
entailment
public static function flush() { $instance = self::getInstance(); $glob = @glob(self::cacheDir() . $instance->_options['file_name_prefix'] . '--*'); if (empty($glob)) { return false; } foreach ($glob as $v) { $fileName = basename($v); $id...
删除所有缓存 @return boolean
entailment
public static function validate($descriptor) { try { new static($descriptor); return []; } catch (Exceptions\SchemaLoadException $e) { return [ new SchemaValidationError(SchemaValidationError::LOAD_FAILED, $e->getMessage()), ]; ...
loads and validates the given descriptor source (php object / string / path to file / url) returns an array of validation error objects. @param mixed $descriptor @return array
entailment
public function castRow($row) { $outRow = []; $validationErrors = []; foreach ($this->fields() as $fieldName => $field) { $value = array_key_exists($fieldName, $row) ? $row[$fieldName] : null; if (in_array($value, $this->missingValues())) { $value = nu...
@param mixed[] $row @return mixed[] @throws Exceptions\FieldValidationException
entailment
public function validateRow($row) { try { $this->castRow($row); return []; } catch (Exceptions\FieldValidationException $e) { return $e->validationErrors; } }
@param array $row @return SchemaValidationError[]
entailment
public function getNextLine() { $row = $this->nextRow; if ($row === null) { if (!$this->resource) { $this->open(); } if ($this->isEof()) { throw new \Exception('EOF'); } $row = $this->nextRow; if ...
@return array @throws DataSourceException
entailment
public function isEof() { if ($this->nextRow) { return false; } else { try { $eof = feof($this->resource); } catch (\Exception $e) { throw new DataSourceException($e->getMessage(), $this->curRowNum); } if ($e...
@return bool @throws DataSourceException
entailment
protected function getRow($continueRow = null) { ++$this->curRowNum; try { $line = fgets($this->resource); } catch (\Exception $e) { throw new DataSourceException($e->getMessage(), $this->curRowNum); } $row = $this->csvDialect->parseRow($line, $contin...
@return array @throws DataSourceException
entailment
public function user(array &$submitted, array $options) { $this->options = $options; $this->submitted = &$submitted; $this->validateUser(); $this->validateBool('status'); $this->validateName(); $this->validateEmail(); $this->validateEmailUniqueUser(); ...
Performs full validation of submitted user data @param array $submitted @param array $options @return array|boolean
entailment
public function login(array &$submitted, array $options = array()) { $this->options = $options; $this->submitted = &$submitted; $this->validateEmail(); $this->validatePasswordUser(); return $this->getResult(); }
Performs full login data validation @param array $submitted @param array $options @return array|boolean
entailment
public function resetPassword(array &$submitted, array $options = array()) { $this->options = $options; $this->submitted = &$submitted; $email = $this->getSubmitted('email'); $password = $this->getSubmitted('password'); if (isset($password)) { $this->validateSta...
Performs password reset validation @param array $submitted @param array $options @return array|boolean
entailment
protected function validateUser() { $id = $this->getUpdatingId(); if ($id === false) { return null; } $data = $this->user->get($id); if (empty($data)) { $this->setErrorUnavailable('update', $this->translation->text('User')); return false...
Validates a user to be updated @return boolean
entailment
protected function validateStatusUser() { $field = 'user'; if ($this->isExcluded($field)) { return null; } $value = $this->getSubmitted($field); if (is_numeric($value)) { $value = $this->user->get($value); } if (empty($value['status...
Validates user status @return boolean
entailment
protected function validateEmailUniqueUser() { $field = 'email'; $value = $this->getSubmitted($field); if ($this->isError($field) || !isset($value)) { return null; } $updating = $this->getUpdating(); if (isset($updating['email']) && $updating['email'] =...
Validates uniqueness of submitted E-mail @return boolean|null
entailment
protected function validateEmailExistsUser() { $field = 'email'; $value = $this->getSubmitted($field); if ($this->isError($field) || !isset($value)) { return null; } $user = $this->user->getByEmail($value); if (empty($user['status'])) { $thi...
Validates an email and checks the responding user enabled @return boolean|null
entailment
protected function validatePasswordUser() { $field = 'password'; if ($this->isExcluded($field)) { return null; } $value = $this->getSubmitted($field); if ($this->isUpdating() && (!isset($value) || $value === '')) { return null; } if...
Validates a user password @return boolean|null
entailment
protected function validatePasswordLengthUser() { $field = 'password'; if ($this->isExcluded($field) || $this->isError($field)) { return null; } $value = $this->getSubmitted($field); if ($this->isUpdating() && (!isset($value) || $value === '')) { re...
Validates password length @return boolean|null
entailment
protected function validatePasswordOldUser() { $field = 'password_old'; if ($this->isExcluded($field)) { return null; } if (!$this->isUpdating() || !empty($this->options['admin'])) { return null; } $password = $this->getSubmitted('password')...
Validates an old user password @return boolean|null
entailment
protected function validateRoleUser() { $field = 'role_id'; $value = $this->getSubmitted($field); if (empty($value)) { return null; } $label = $this->translation->text('Role'); if (!is_numeric($value)) { $this->setErrorNumeric($field, $label...
Validates a user role @return boolean|null
entailment
protected function validateTimezoneUser() { $field = 'timezone'; if ($this->isExcluded($field)) { return null; } $value = $this->getSubmitted($field); if (!isset($value)) { $this->unsetSubmitted($field); return null; } $...
Validates "timezone" field @return bool|null
entailment
public function get($store = null) { if (!$this->db->isInitialized()) { return array(); } if (!isset($store)) { $url = $this->server->httpHost(); $basepath = trim($this->request->base(true), '/'); $store = trim("$url/$basepath", '/'); ...
Loads a store @param integer|string|null $store @return array
entailment
public function getDefault($load = false) { $store_id = $this->config->get('store', 1); if ($load) { return $this->get($store_id); } return (int) $store_id; }
Returns a default store @param boolean $load @return array|integer
entailment
protected function deleteLinked($store_id) { $this->db->delete('triggers', array('store_id' => $store_id)); $this->db->delete('wishlist', array('store_id' => $store_id)); $this->db->delete('collection', array('store_id' => $store_id)); $this->db->delete('product_sku', array('store_id...
Delete all database rows related to the store @param int $store_id
entailment
public function canDelete($store_id) { if ($this->isDefault($store_id)) { return false; } $sql = 'SELECT NOT EXISTS (SELECT store_id FROM product WHERE store_id=:id) AND NOT EXISTS (SELECT store_id FROM category_group WHERE store_id=:id) AND NOT E...
Whether the store can be deleted @param integer $store_id @return boolean
entailment
public function getTranslation($item, $langcode, $store = null) { $config = $this->getConfig(null, $store); if (!empty($config['translation'][$langcode][$item])) { return $config['translation'][$langcode][$item]; } if (isset($config[$item])) { return $config...
Returns a translatable store configuration item @param string $item @param string $langcode @param mixed $store @return string
entailment
public function getConfig($item = null, $store = null) { if (empty($store)) { $store = $this->get(); } elseif (!is_array($store)) { $store = $this->get($store); } if (empty($store['data'])) { $store['data'] = $this->getDefaultData(); } ...
Returns a value from a given config item @param mixed $item @param mixed $store @return mixed
entailment
public function delete($address_id, $check = true) { $result = null; $this->hook->attach('address.delete.before', $address_id, $check, $result, $this); if (isset($result)) { return (bool) $result; } if ($check && !$this->canDelete($address_id)) { ret...
Deletes an address @param integer $address_id @param bool $check @return boolean
entailment
public function get($condition) { if (!is_array($condition)) { $condition = array('address_id' => $condition); } $result = &gplcart_static(gplcart_array_hash(array('address.get' => $condition))); if (isset($result)) { return $result; } $resu...
Loads an address from the database @param int|array|string $condition @return array
entailment
public function getTranslatedList($user_id, $status = true) { $conditions = array( 'status' => $status, 'user_id' => $user_id ); $addresses = array(); foreach ((array) $this->getList($conditions) as $address_id => $address) { $addresses[$address_i...
Returns an array of addresses with translated address fields for the user @param integer $user_id @param boolean $status @return array
entailment
public function getTranslated(array $address, $both = false) { $default = $this->country->getDefaultFormat(); $format = gplcart_array_merge($default, $address['country_format']); gplcart_array_sort($format); $results = array(); foreach ($format as $key => $data) { ...
Returns an array of translated address fields @param array $address @param boolean $both @return array
entailment
public function getExceeded($user_id, $existing = null) { $limit = $this->getLimit($user_id); if (empty($limit)) { return array(); } if (!isset($existing)) { $existing = $this->getList(array('user_id' => $user_id)); } $count = count($existin...
Returns an array of exceeded addresses for the user ID @param string|integer $user_id @param null|array $existing @return array
entailment
public function getLimit($user_id) { if (empty($user_id) || !is_numeric($user_id)) { return (int) $this->config->get('user_address_limit_anonymous', 1); } return (int) $this->config->get('user_address_limit', 4); }
Returns a number of addresses the user can have @param string|integer @return integer
entailment
protected function prepareList(array $addresses, array $data) { $countries = $this->country->getList(); $list = array(); foreach ($addresses as $address_id => $address) { $list[$address_id] = $address; if (empty($data['status'])) { continue; // Do n...
Returns an array of filtered addresses @param array $addresses @param array $data @return array
entailment
public function matchRequest(SymfonyRequest $request) { $laravelRequest = LaravelRequest::createFromBase($request); $route = $this->findRoute($laravelRequest); $route->setParameter('_module', $this->moduleName); return $route; }
Given a request object, find the matching route. @param Request $request @return \Illuminate\Routing\Route
entailment
public function selectCompare() { $this->controlProductsCompare(); $this->setTitleSelectCompare(); $this->setBreadcrumbSelectCompare(); $this->setData('products', $this->getProductsSelectCompare()); $this->outputSelectCompare(); }
Page callback Displays the select to compare page
entailment
protected function controlProductsCompare() { $options = array( 'status' => 1, 'store_id' => $this->store_id, 'product_id' => $this->product_compare->getList() ); if (!empty($options['product_id'])) { $existing = array_keys($this->product->get...
Make sure that products saved in cookie are all valid and available to the user If some products were removed, disabled or moved to another store they will be removes from cookie
entailment
protected function getProductsSelectCompare() { $conditions = array( 'product_id' => $this->getProductComparison()); $options = array( 'view' => $this->configTheme('compare_view', 'grid'), 'buttons' => array('cart_add', 'wishlist_add', 'compare_remove') )...
Returns an array of products re-indexed by a class ID @return array
entailment
protected function reindexProductsCompare(array $products) { $prepared = array(); foreach ($products as $product_id => $product) { $prepared[$product['product_class_id']][$product_id] = $product; } return $prepared; }
Returns an array of products indexed by a class ID @param array $products @return array
entailment
public function compareCompare($ids) { $this->setProductCompare($ids); $this->controlAccessCompareCompare(); $this->setTitleCompareCompare(); $this->setBreadcrumbCompareCompare(); $this->setData('products', $this->data_products); $this->setData('fields', $this->getFi...
Page callback Displays the product comparison page @param string $ids
entailment
protected function setProductCompare($string) { $ids = array_filter(array_map('trim', explode(',', $string)), 'ctype_digit'); $this->data_products = $this->getProductsCompare($ids); $this->prepareProductsCompare($this->data_products); }
Set an array of product IDs to compare @param string $string
entailment
protected function prepareProductsCompare(array &$products) { foreach ($products as $product_id => &$product) { $product['field'] = $this->product_field->getList($product_id); $this->setItemProductFields($product, $this->image, $this->product_class); } }
Prepare an array of products to be compared @param array $products
entailment
protected function getFieldsCompare(array $products) { $labels = array(); foreach ($products as $product) { if (!empty($product['field_value_labels'])) { foreach ($product['field_value_labels'] as $type => $fields) { foreach (array_keys($fields) as $f...
Returns an array of all fields for the given products @param array $products @return array
entailment
protected function setBreadcrumbCompareCompare() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('/'), 'text' => $this->text('Home')); $breadcrumbs[] = array( 'url' => $this->url('compare'), 'text' => $this->text('Select...
Sets breadcrumbs on the product comparison page
entailment
public function format($amount, $currency_code, $decimal = true, $full = true) { $currency = $this->currency->get($currency_code); if (empty($currency)) { return 'n/a'; } if ($decimal) { $amount = $this->decimal($amount, $currency_code); } /...
Format a price @param integer $amount @param string $currency_code @param bool $decimal @param bool $full @return string
entailment
public function formatTemplate($amount, array $data) { $placeholders = array(); foreach (array_keys($data) as $key) { $placeholders["%$key"] = $key; } $formatted = gplcart_string_replace($data['template'], $placeholders, $data); return $amount < 0 ? "-$formatted...
Format an amount using the currency template @param int|float $amount @param array $data @return string
entailment
public function formatNumber($amount, array $currency) { $rounded = $this->round(abs($amount), $currency); return number_format($rounded, $currency['decimals'], $currency['decimal_separator'], $currency['thousands_separator']); }
Format an amount with grouped thousands @param int|float $amount @param array $currency @return string
entailment
public function decimal($amount, $currency_code) { static $divisors = array(); if (empty($divisors[$currency_code])) { $currency = $this->currency->get($currency_code); $divisors[$currency_code] = pow(10, $currency['decimals']); } return $amount / $divisors[...
Converts an amount from minor to major units @param integer $amount @param string $currency_code @return float
entailment
public function round($amount, array $currency) { if (empty($currency['rounding_step'])) { return round($amount, $currency['decimals']); } $modifier = 1 / $currency['rounding_step']; return round($amount * $modifier) / $modifier; }
Rounds an amount @param integer $amount @param array $currency @return integer
entailment
public function amount($decimal, $currency_code = null, $round = true) { static $factors = array(); if (empty($currency_code)) { $currency_code = $this->currency->getDefault(); } if (empty($factors[$currency_code])) { $currency = $this->currency->get($curren...
Converts a price from major to minor units @param float $decimal @param string|null $currency_code @param boolean $round @return integer
entailment
public function convert($amount, $from_currency, $to_currency) { return $this->currency->convert($amount, $from_currency, $to_currency); }
Converts currencies @param int $amount @param string $from_currency @param string $to_currency @return int
entailment
public function setItemTotalFormattedNumber(array &$item, $price_model) { $item['total_formatted_number'] = $price_model->format($item['total'], $item['currency'], true, false); }
Adds "total_formatted_number" key @param array $item @param \gplcart\core\models\Price $price_model
entailment
public function setItemPriceFormatted(array &$item, $price_model, $currency = null) { if (!isset($currency)) { $currency = $item['currency']; } $price = $price_model->convert($item['price'], $item['currency'], $currency); $item['price_formatted'] = $price_model->format($...
Add keys with formatted prices @param array $item @param \gplcart\core\models\Price $price_model @param string|null $currency
entailment
public function setItemPriceCalculated(array &$item, $product_model) { $calculated = $product_model->calculate($item); if ($item['price'] != $calculated) { $item['original_price'] = $item['price']; } $item['price'] = $calculated; }
Adjust an original price according to applied price rules @param array $item @param \gplcart\core\models\Product $product_model
entailment
public function page(array &$submitted, array $options = array()) { $this->options = $options; $this->submitted = &$submitted; $this->validatePage(); $this->validateBool('status'); $this->validateBool('blog_post'); $this->validateTitle(); $this->validateDescr...
Performs page data validation @param array $submitted @param array $options @return array|boolean
entailment
protected function validatePage() { $id = $this->getUpdatingId(); if ($id === false) { return null; } $data = $this->page->get($id); if (empty($data)) { $this->setErrorUnavailable('update', $this->translation->text('Page')); return false...
Validates a page to be updated @return boolean|null
entailment
protected function validateCategoryPage() { $field = 'category_id'; $value = $this->getSubmitted($field); if (empty($value)) { return null; } $label = $this->translation->text('Category'); if (!is_numeric($value)) { $this->setErrorNumeric($f...
Validates a category ID @return boolean|null
entailment
protected function validatePost($postTypeModel, $request, $validationRules) { // Lets receive the current items from the post type validation array if(array_key_exists('post_name', $validationRules) && !is_array($validationRules['post_name'])){ $exploded = explode('|', $validationRules['post_name']...
Validating the creation and change of a post
entailment
public function setToken($token = null) { if (isset($token)) { return $this->token = $token; } return $this->token = gplcart_string_encode(crypt(session_id(), $this->config->getKey())); }
Sets a token @param string|null $token @return string
entailment
protected function setInstanceProperties() { $this->hook = $this->getInstance('gplcart\\core\\Hook'); $this->route = $this->getInstance('gplcart\\core\\Route'); $this->module = $this->getInstance('gplcart\\core\\Module'); $this->config = $this->getInstance('gplcart\\core\\Config'); ...
Sets instance properties
entailment
protected function setRouteProperties() { $this->current_route = $this->route->get(); $this->path = $this->url->path(); $this->is_backend = $this->url->isBackend(); $this->is_install = $this->url->isInstall(); $this->host = $this->server->httpHost(); $this->scheme =...
Sets the current route data
entailment