sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
public function createService(ServiceLocatorInterface $serviceLocator)
{
$request = $serviceLocator->get('Request');
$requestContext = $serviceLocator->get('RouterRequestContext');
$routerOptions = array();
$logger = $serviceLocator->has('Logger') ? $serviceLocator->get('Logger') : null;
$chainRouter = new ChainRouter($logger);
if($serviceLocator->has('RoutingCache')) {
$chainRouter->setCache($serviceLocator->get('RoutingCache'));
}
$chainRouter->setContext($requestContext);
$allModuleRoutes = $serviceLocator->get('ModuleDefaultListener')->getRoutes();
// For each module, add a matching instance type to the chain router
foreach ($allModuleRoutes as $moduleName => $moduleRoutingResponse) {
switch (true) {
// @todo - move this to a separate method()
case $moduleRoutingResponse instanceof SymfonyRouteCollection:
$sfRouter = new SymfonyRouter($requestContext, $moduleRoutingResponse, $routerOptions, $logger);
$sfRouterWrapper = new SymfonyRouterWrapper($sfRouter);
$chainRouter->add($sfRouterWrapper);
break;
// @todo - move this to a separate method()
case $moduleRoutingResponse instanceof AuraRouter:
$auraRouterWrapper = new AuraRouterWrapper($moduleRoutingResponse);
$chainRouter->add($auraRouterWrapper);
break;
// @todo - move this to a separate method()
case $moduleRoutingResponse instanceof LaravelRouter:
$laravelRequest = new LaravelRequest();
$laravelUrlGenerator = new LaravelUrlGenerator($moduleRoutingResponse->getRoutes(), $laravelRequest);
$laravelRouterWrapper = new LaravelRouterWrapper(
$moduleRoutingResponse, $laravelRequest, $laravelUrlGenerator
);
// @todo - solve this problem
// $laravelRouterWrapper->setModuleName($this->getName());
$chainRouter->add($laravelRouterWrapper);
break;
case $moduleRoutingResponse instanceof FastRouteWrapper:
$chainRouter->add($moduleRoutingResponse);
break;
default:
throw new \Exception('Unexpected routes value return from module: ' . $moduleName .
'. found value of type: ' . gettype($moduleRoutingResponse));
}
}
return $chainRouter;
} | @todo - move this to a separate method() - consider how to inject custom-defined arbitrary chain router entries
@param ServiceLocatorInterface $serviceLocator
@throws \Exception
@return ChainRouter | entailment |
public function getList()
{
$result = &gplcart_static('product.compare.list');
if (isset($result)) {
return (array) $result;
}
$this->hook->attach('product.compare.list.before', $result, $this);
if (isset($result)) {
return (array) $result;
}
$cookie = $this->request->cookie('product_compare', '', 'string');
$result = array_filter(array_map('trim', explode('|', urldecode($cookie))), 'ctype_digit');
$this->hook->attach('product.compare.list.after', $result, $this);
return $result;
} | Returns an array of product ID to be compared
@return array | entailment |
public function add($product_id)
{
$result = null;
$this->hook->attach('product.compare.add.before', $product_id, $result, $this);
if (isset($result)) {
return (bool) $result;
}
$product_ids = $this->getList();
if (in_array($product_id, $product_ids)) {
return false;
}
array_unshift($product_ids, $product_id);
$this->controlLimit($product_ids);
$result = $this->set($product_ids);
$this->hook->attach('product.compare.add.after', $product_id, $result, $this);
return (bool) $result;
} | Adds a product to comparison
@param integer $product_id
@return boolean | entailment |
public function delete($product_id)
{
$result = null;
$this->hook->attach('product.compare.delete.before', $product_id, $result, $this);
if (isset($result)) {
return (bool) $result;
}
$compared = $this->getList();
if (empty($compared)) {
return false;
}
$product_ids = array_flip($compared);
unset($product_ids[$product_id]);
$result = $this->set(array_keys($product_ids));
$this->hook->attach('product.compare.delete.after', $product_id, $result, $this);
return (bool) $result;
} | Removes a products from comparison
@param integer $product_id
@return array|boolean | entailment |
public function set(array $product_ids)
{
$lifespan = $this->getCookieLifespan();
$result = $this->request->setCookie('product_compare', implode('|', (array) $product_ids), $lifespan);
gplcart_static_clear();
return $result;
} | Saves an array of product ID in cookie
@param array $product_ids
@return boolean | entailment |
protected function controlLimit(array &$product_ids)
{
$limit = $this->getLimit();
if (!empty($limit)) {
$product_ids = array_slice($product_ids, 0, $limit);
}
} | Reduces a number of items to save
@param array $product_ids | entailment |
public function install(array $data, $db)
{
$this->db = $db;
$this->data = $data;
try {
$this->start();
$this->process();
return $this->finish();
} catch (Exception $ex) {
return array(
'redirect' => '',
'severity' => 'warning',
'message' => $ex->getMessage()
);
}
} | Performs full system installation
@param array $data
@param \gplcart\core\Database $db
@return array | entailment |
public function parseParams($argv)
{
if (is_string($argv)) {
$argv = gplcart_string_explode_whitespace($argv);
}
array_shift($argv);
$out = array();
for ($i = 0, $j = count($argv); $i < $j; $i++) {
$key = null;
$arg = $argv[$i];
if (substr($arg, 0, 2) === '--') {
$pos = strpos($arg, '=');
if ($pos === false) {
$key = substr($arg, 2);
if ($i + 1 < $j && $argv[$i + 1][0] !== '-') {
$value = $argv[$i + 1];
$i++;
} else {
$value = isset($out[$key]) ? $out[$key] : true;
}
$out[$key] = $value;
continue;
}
$key = substr($arg, 2, $pos - 2);
$value = substr($arg, $pos + 1);
$out[$key] = $value;
continue;
}
if (substr($arg, 0, 1) === '-') {
if (substr($arg, 2, 1) === '=') {
$key = substr($arg, 1, 1);
$value = substr($arg, 3);
$out[$key] = $value;
continue;
}
foreach (str_split(substr($arg, 1)) as $char) {
$key = $char;
$value = isset($out[$key]) ? $out[$key] : true;
$out[$key] = $value;
}
if ($i + 1 < $j && $argv[$i + 1][0] !== '-') {
$out[$key] = $argv[$i + 1];
$i++;
}
continue;
}
$value = $arg;
$out[] = $value;
}
return $out;
} | Parses command line parameters
@param array|string $argv
@return array | entailment |
public function in($format = '')
{
if (empty($format)) {
$line = fgets(STDIN);
} else {
$line = fscanf(STDIN, $format . PHP_EOL, $line);
}
return trim($line);
} | Reads a user input
@param string $format
@return string | entailment |
public function prompt($question, $default = null, $marker = ': ')
{
if (isset($default) && strpos($question, '[') === false) {
$question .= ' [default: ' . $default . ']';
}
$this->out($question . $marker);
$input = $this->in();
if ($input === '') {
return $default;
}
return $input;
} | Displays an input prompt
@param string $question
@param string|null $default
@param string $marker
@return mixed | entailment |
public function menu($items, $default = null, $title = 'Choose an item')
{
if (isset($items[$default]) && strpos($title, '[') === false) {
$title .= ' [default: ' . $items[$default] . ']';
}
$this->line(sprintf('%s: ', $title));
$i = 1;
$keys = array();
foreach ($items as $key => $item) {
$keys[$i] = $key;
$this->line(sprintf(' %d. %s', $i, $item));
$i++;
}
$selected = $this->in();
if ($selected === '') {
return $default;
}
if (isset($keys[$selected])) {
return $keys[$selected];
}
return $selected;
} | Displays a menu where a user can enter a number to choose an option
@param array $items An array like array('key' => 'Label')
@param mixed $default
@param string $title
@return mixed | entailment |
public function choose($question, $choice = 'yn', $default = 'n')
{
if (!is_string($choice)) {
$choice = implode('', $choice);
}
$lowercase = str_ireplace($default, strtoupper($default), strtolower($choice));
$choices = trim(implode('/', preg_split('//', $lowercase)), '/');
$line = $this->prompt(sprintf('%s [%s]', $question, $choices), $default, '');
if (stripos($choice, $line) !== false) {
return strtolower($line);
}
return strtolower($default);
} | Presents a user with a multiple choice questions
@param string $question
@param string|array $choice
@param string $default
@return string | entailment |
public function exec($command, $message = true, $output = true)
{
$shell_output = array();
exec($command . ' 2>&1', $shell_output, $result);
if (empty($result)) {
if ($message) {
$this->out('OK');
}
} else {
if ($message) {
$this->error('Error');
}
}
if ($output) {
$this->out(implode(PHP_EOL, $shell_output));
}
return $result;
} | Executes a Shell command using exec() function
@param string $command
@param boolean $message
@param boolean $output
@return integer | entailment |
public function table(array $data)
{
$columns = array();
foreach ($data as $rkey => $row) {
foreach ($row as $ckey => $cell) {
$length = strlen($cell);
if (empty($columns[$ckey]) || $columns[$ckey] < $length) {
$columns[$ckey] = $length;
}
}
}
$table = '';
foreach ($data as $rkey => $row) {
foreach ($row as $ckey => $cell) {
$table .= str_pad($cell, $columns[$ckey]) . ' ';
}
$table .= PHP_EOL;
}
$this->line($table);
} | Output simple table
@param array $data | entailment |
public function addConfig($resource, $type)
{
if (!$this->skipConfig) {
$this->configs[] = array(
'resource' => $resource,
'type' => $type,
);
}
return $this;
} | @param mixed $resource The resource
@param string $type The resource type
@return $this | entailment |
public function set($data = null)
{
$this->server = isset($data) ? $data : $_SERVER;
return $this;
} | Sets $_SERVER variables
@param null|array $data
@return $this | entailment |
public function get($name = null, $default = '', $sanitize = true)
{
if (!isset($name)) {
return $this->server;
}
if (!array_key_exists($name, $this->server)) {
return $default;
}
if (is_array($this->server[$name])) {
gplcart_array_trim($this->server[$name], $sanitize);
} else {
$this->server[$name] = trim($this->server[$name]);
if ($sanitize) {
$this->server[$name] = filter_var($this->server[$name], FILTER_SANITIZE_STRING);
}
}
return $this->server[$name];
} | Returns a server data
@param string $name
@param mixed $default
@param bool $sanitize
@return mixed | entailment |
public function header($name, $default = null, $sanitize = true)
{
$headers = $this->headers();
$name = ucfirst(strtolower($name));
if (array_key_exists($name, $headers)) {
return $sanitize ? filter_var($headers[$name], FILTER_SANITIZE_STRING) : $headers[$name];
}
return $default;
} | Returns an HTTP header
@param string $name
@param mixed $default
@param bool $sanitize
@return string | entailment |
public function headers()
{
if (function_exists('getallheaders')) {
$headers = getallheaders();
return empty($headers) ? array() : $headers;
}
$headers = array();
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
$headers[$key] = $value;
}
}
return $headers;
} | Returns an array of HTTP headers
$_SERVER is not entirely complete (e.g doesn't contain Authorization header)
so first it tries to use getallheaders() function which works only on Apache server
@return array | entailment |
public function get($key)
{
$key = strtolower($key);
if (!isset($this->services[$key])) {
throw new \InvalidArgumentException('Service not found: ' . $key);
}
// Have we been here before?
if (isset($this->loadedService[$key])) {
return $this->loadedService[$key];
}
if (!$this->services[$key] instanceof Service) {
$this->loadedService[$key] = $this->services[$key];
return $this->loadedService[$key];
}
// It's a Service instance, lets do some extra stuff.
if (!$this->services[$key]->hasClassName()) {
throw new \Exception('Unable to find class name from definition: ' . $key);
}
$className = $this->services[$key]->getClassName();
$instance = new $className();
if ($this->services[$key]->hasFactoryMethod()) {
call_user_func($instance, $this->services[$key]->getFactoryMethod());
}
$this->loadedService[$key] = $instance;
return $this->loadedService[$key];
} | Get a registered service by its name.
@param string $key
@throws \Exception|\InvalidArgumentException
@return mixed | entailment |
protected function validateCastValue($val)
{
if (isset($this->descriptor()->bareNumber) && $this->descriptor()->bareNumber === false) {
return mb_ereg_replace('((^\D*)|(\D*$))', '', $val);
}
$isPercent = false;
if (is_string($val)) {
if (substr($val, -1) == '%') {
$val = rtrim($val, '%');
$isPercent = true;
}
if (isset($this->descriptor()->groupChar)) {
$val = str_replace($this->descriptor()->groupChar, '', $val);
}
if (isset($this->descriptor()->decimalChar) && $this->descriptor()->decimalChar != '.') {
$val = str_replace($this->descriptor()->decimalChar, '.', $val);
}
}
if (!is_numeric($val)) {
throw $this->getValidationException('value must be numeric', $val);
} else {
$val = (float) $val;
if ($isPercent) {
$val = $val / 100;
}
return $val;
}
} | @param mixed $val
@return float
@throws \frictionlessdata\tableschema\Exceptions\FieldValidationException; | entailment |
public function getCollectionItems(array $conditions, array $options, $model)
{
$conditions += array(
'status' => 1,
'store_id' => $this->getStoreId()
);
$items = $model->getItems($conditions);
if (!empty($items)) {
$item = reset($items);
$options += array(
'entity' => $item['collection_item']['type'],
'template_item' => $item['collection_handler']['template']['item']
);
$this->prepareEntityItems($items, $options);
}
return $items;
} | Returns an array of collection items
@param array $conditions
@param array $options
@param \gplcart\core\models\CollectionItem $model
@return array | entailment |
public function listCategory()
{
$this->setTitleListCategory();
$this->setBreadcrumbListCategory();
$this->setData('categories', $this->data_categories);
$this->outputListCategory();
} | Page callback
Displays the catalog page | entailment |
public function indexCategory($category_id)
{
$this->setCategory($category_id);
$this->setTitleIndexCategory();
$this->setBreadcrumbIndexCategory();
$this->setHtmlFilterIndexCategory();
$this->setTotalIndexCategory();
$this->setFilterIndexCategory();
$this->setPagerIndexCategory();
$this->setListProductCategory();
$this->setChildrenCategory();
$this->setData('category', $this->data_category);
$this->setDataMenuIndexCategory();
$this->setDataImagesIndexCategory();
$this->setDataNavbarIndexCategory();
$this->setDataProductsIndexCategory();
$this->setDataChildrenIndexCategory();
$this->setMetaIndexCategory();
$this->outputIndexCategory();
} | Page callback
Displays the category page
@param integer $category_id | entailment |
protected function setFilterIndexCategory()
{
$default = array(
'view' => $this->configTheme('catalog_view', 'grid'),
'sort' => $this->configTheme('catalog_sort', 'price'),
'order' => $this->configTheme('catalog_order', 'asc')
);
$this->setFilter(array(), $this->getFilterQuery($default));
} | Sets filter on the category page | entailment |
protected function setTotalIndexCategory()
{
$options = $this->query_filter;
$options['count'] = true;
$options['category_id'] = $this->data_category['category_id'];
return $this->data_total = (int) $this->product->getList($options);
} | Sets a total number of products found for the category
@return int | entailment |
protected function setPagerIndexCategory()
{
$pager = array(
'total' => $this->data_total,
'query' => $this->query_filter,
'limit' => $this->configTheme('catalog_limit', 20)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function setDataImagesIndexCategory()
{
$options = array('imagestyle' => $this->configTheme('image_style_category', 3));
$this->setItemThumb($this->data_category, $this->image, $options);
$this->setData('images', $this->render('category/images', array('category' => $this->data_category)));
} | Sets the category images | entailment |
protected function setDataNavbarIndexCategory()
{
$data = array(
'total' => $this->data_total,
'view' => $this->query_filter['view'],
'quantity' => count($this->data_products),
'sort' => "{$this->query_filter['sort']}-{$this->query_filter['order']}"
);
$this->setData('navbar', $this->render('category/navbar', $data));
} | Sets navigation bar on the category page | entailment |
protected function setListProductCategory()
{
$options = $this->query_filter;
$options['placeholder'] = true;
$conditions = array(
'limit' => $this->data_limit,
'category_id' => $this->data_category['category_id']) + $this->query_filter;
$this->data_products = $this->getProducts($conditions, $options);
} | Sets an array of products for the category | entailment |
protected function setMetaIndexCategory()
{
$this->setMetaEntity($this->data_category);
if (empty($this->data_children) && empty($this->data_products)) {
$this->setMeta(array('name' => 'robots', 'content' => 'noindex'));
}
} | Sets the meta tags on the category page | entailment |
protected function setChildrenCategory()
{
$this->data_children = array();
foreach ($this->data_categories as $item) {
if (in_array($this->data_category['category_id'], $item['parents'])) {
$this->data_children[] = $item;
}
}
} | Sets an array of children categories for the given category | entailment |
protected function setTitleIndexCategory()
{
$metatitle = $this->data_category['meta_title'];
if (empty($metatitle)) {
$metatitle = $this->data_category['title'];
}
$this->setTitle($metatitle, false);
$this->setPageTitle($this->data_category['title']);
} | Sets titles on the category page | entailment |
protected function setCategory($category_id)
{
$options = array(
'category_id' => $category_id,
'language' => $this->langcode,
'store_id' => $this->store_id
);
$this->data_category = $this->category->get($options);
if (empty($this->data_category['status'])) {
$this->outputHttpStatus(404);
}
$this->prepareCategory($this->data_category);
} | Sets a category data
@param integer $category_id | entailment |
public function doRun(InputInterface $input, OutputInterface $output)
{
$this->registerCommands();
if (true === $input->hasParameterOption(array('--shell', '-s'))) {
$shell = new Shell($this);
$shell->setProcessIsolation($input->hasParameterOption(array('--process-isolation')));
$shell->run();
return 0;
}
return parent::doRun($input, $output);
} | Runs the current application.
@param InputInterface $input An Input instance
@param OutputInterface $output An Output instance
@return int 0 if everything went fine, or an error code | entailment |
public function indexFront()
{
$this->setTitleIndexFront();
$this->setDataCollectionFront('page');
$this->setDataCollectionFront('file');
$this->setDataCollectionFront('product');
$this->outputIndexFront();
} | Displays the store front page | entailment |
protected function setDataCollectionFront($type)
{
$collection_id = $this->getStore("data.collection_$type");
if (!empty($collection_id)) {
$conditions = array('collection_id' => $collection_id);
$options = array('imagestyle' => $this->configTheme("image_style_collection_$type"));
$items = $this->getCollectionItems($conditions, array_filter($options), $this->collection_item);
$this->setData("collection_$type", $this->getWidgetCollection($items));
}
} | Adds a collection block
@param string $type | entailment |
protected function getPostType($group)
{
// Receive the config variable where we have whitelisted all models
$nikuConfig = config('niku-cms');
// Validating if the model exists in the array
if(array_key_exists($group, $nikuConfig['config_types'])){
// Setting the model class
$postTypeModel = new $nikuConfig['config_types'][$group];
// Lets validate if the request has got the correct authorizations set
if(!$this->authorizations($postTypeModel)){
return false;
}
return $postTypeModel;
} else {
return false;
}
} | Validating if the post type exists and returning the model. | entailment |
public function add(array $product, array $data)
{
$result = array();
$this->hook->attach('product.compare.add.product.before', $product, $data, $result, $this);
if (!empty($result)) {
return (array) $result;
}
if (!$this->compare->add($product['product_id'])) {
return $this->getResultError();
}
$result = $this->getResultAdded();
$this->hook->attach('product.compare.add.product.after', $product, $data, $result, $this);
return (array) $result;
} | Adds a product to comparison and returns an array of results
@param array $product
@param array $data
@return array | entailment |
public function delete($product_id)
{
$result = null;
$this->hook->attach('product.compare.delete.product.before', $product_id, $result, $this);
if (!empty($result)) {
return (array) $result;
}
if (!$this->compare->delete($product_id)) {
return $this->getResultError();
}
$result = $this->getResultDeleted();
$this->hook->attach('product.compare.delete.product.after', $product_id, $result, $this);
return (array) $result;
} | Removes a product from comparison and returns an array of result data
@param integer $product_id
@return array | entailment |
protected function getResultAdded()
{
$quantity = count($this->compare->getList());
if ($quantity < $this->compare->getLimit()) {
$quantity++;
}
$message = $this->translation->text('Product has been added to <a href="@url">comparison</a>', array(
'@url' => $this->url->get('compare')));
return array(
'redirect' => '',
'severity' => 'success',
'quantity' => $quantity,
'message' => $message
);
} | Returns an array of resulting data when a product has been added to comparison
@return array | entailment |
public function up()
{
Schema::create('cms_taxonomy', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('post_id')->unsigned();
$table->bigInteger('taxonomy_post_id')->unsigned();
$table->string('taxonomy')->nullable();
$table->longText('custom')->nullable();
$table->bigInteger('menu_order')->nullable();
$table->bigInteger('post_parent')->nullable();
$table->foreign('post_id')->references('id')->on('cms_posts')->onDelete('cascade');
$table->foreign('taxonomy_post_id')->references('id')->on('cms_posts')->onDelete('cascade');
$table->timestamps();
});
} | Run the migrations.
@return void | entailment |
public function parse($controller)
{
list($module, $moduleName, $controller, $action) = $this->getPartsFromControllerName($controller);
if (null === $module) {
// this throws an exception if there is no such module
$msg = sprintf('Unable to find controller "%s:%s" - module alias "%s" does not exist.', $moduleName, $controller, $moduleAlias);
} else {
$class = $module->getNamespace() . '\\Controller\\' . $controller;
if (class_exists($class)) {
return $class . '::' . $action . 'Action';
}
$msg = sprintf('Unable to find controller "%s:%s" - class "%s" does not exist.', $moduleName, $controller, $class);
}
throw new \InvalidArgumentException($msg);
} | Converts a short notation a:b:c to a class::method.
@param string $controller A short notation controller (a:b:c)
@throws \InvalidArgumentException when the specified module is not enabled
or the controller cannot be found
@return string A string with class::method | entailment |
private function getPartsFromControllerName($controller)
{
if (3 != count($parts = explode(':', $controller))) {
throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid a:b:c controller string.', $controller));
}
list($moduleName, $controller, $action) = $parts;
$controller = str_replace('/', '\\', $controller);
$module = $this->moduleManager->getModule($moduleName);
if (!is_object($module)) {
throw new \RuntimeException(sprintf(
'Unable to locate module: %s, when parsing controller: %s',
$moduleName, $controller
));
}
$moduleName = $module->getName();
return [$module, $moduleName, $controller, $action];
} | @param string $controller
@return array | entailment |
public function countryCode(array $values)
{
$existing = array_filter($values, function ($code) {
$country = $this->country->get($code);
return isset($country['code']);
});
if (count($values) != count($existing)) {
return $this->translation->text('@name is unavailable', array(
'@name' => $this->translation->text('Country')));
}
return true;
} | Validates the country code condition
@param array $values
@return boolean|string | entailment |
public function stateId(array $values)
{
$count = count($values);
$ids = array_filter($values, 'ctype_digit');
if ($count != count($ids)) {
return $this->translation->text('@field has invalid value', array(
'@field' => $this->translation->text('Condition')));
}
$existing = array_filter($values, function ($state_id) {
$state = $this->state->get($state_id);
return isset($state['state_id']);
});
if ($count != count($existing)) {
return $this->translation->text('@name is unavailable', array(
'@name' => $this->translation->text('Country state')));
}
return true;
} | Validates the country state condition
@param array $values
@return boolean|string | entailment |
public function zoneId(array $values, $operator)
{
if (!in_array($operator, array('=', '!='))) {
return $this->translation->text('Unsupported operator');
}
$zone = $this->zone->get(reset($values));
if (empty($zone)) {
return $this->translation->text('@name is unavailable', array(
'@name' => $this->translation->text('Condition')));
}
return true;
} | Validates a zone ID condition
@param array $values
@param string $operator
@return boolean | entailment |
public function getUser($nullIfGuest = false)
{
$user = $this->user;
$token = $this->tokenStorage->getToken();
if (!$user && null !== $token) {
$user = $token->getUser();
}
if (!$user instanceof User) {
if ($nullIfGuest) {
return null;
}
$user = new User(true);
}
return $user;
} | @param bool $nullIfGuest
@return User|null | entailment |
public function listPage()
{
$this->actionPage();
$this->setTitleListPage();
$this->setBreadcrumbListPage();
$this->setFilterListPage();
$this->setPagerListPage();
$this->setData('pages', $this->getListPage());
$this->outputListPage();
} | Displays the page overview | entailment |
protected function actionPage()
{
list($selected, $action, $value) = $this->getPostedAction();
$deleted = $updated = 0;
foreach ($selected as $page_id) {
if ($this->access('page_edit')) {
if ($action === 'status') {
$updated += (int) $this->page->update($page_id, array('status' => $value));
} else if ($action === 'blog_post') {
$updated += (int) $this->page->update($page_id, array('blog_post' => $value));
}
}
if ($action === 'delete' && $this->access('page_delete')) {
$deleted += (int) $this->page->delete($page_id);
}
}
if ($updated > 0) {
$this->setMessage($this->text('Updated %num item(s)', array('%num' => $updated)), 'success');
}
if ($deleted > 0) {
$this->setMessage($this->text('Deleted %num item(s)', array('%num' => $deleted)), 'success');
}
} | Applies an action to the selected pages | entailment |
protected function setPagerListPage()
{
$conditions = $this->query_filter;
$conditions['count'] = true;
$pager = array(
'query' => $this->query_filter,
'total' => (int) $this->page->getList($conditions)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function getListPage()
{
$conditions = $this->query_filter;
$conditions['limit'] = $this->data_limit;
$list = (array) $this->page->getList($conditions);
$this->prepareListPage($list);
return $list;
} | Returns an array of pages
@return array | entailment |
protected function prepareListPage(array &$list)
{
foreach ($list as &$item) {
$this->setItemUrlEntity($item, $this->store, 'page');
}
} | Prepare an array of pages
@param array $list | entailment |
public function editPage($page_id = null)
{
$this->setPage($page_id);
$this->setTitleEditPage();
$this->setBreadcrumbEditPage();
$this->setData('page', $this->data_page);
$this->setData('languages', $this->language->getList(array('enabled' => true)));
$this->submitEditPage();
$this->setDataImagesEditPage();
$this->setDataCategoriesEditPage();
$this->outputEditPage();
} | Displays the page edit form
@param integer|null $page_id | entailment |
protected function setPage($page_id)
{
$this->data_page = array();
if (is_numeric($page_id)) {
$conditions = array(
'language' => 'und',
'page_id' => $page_id
);
$this->data_page = $this->page->get($conditions);
if (empty($this->data_page)) {
$this->outputHttpStatus(404);
}
$this->preparePage($this->data_page);
}
} | Set a page data
@param integer $page_id | entailment |
protected function preparePage(array &$page)
{
$user = $this->user->get($page['user_id']);
$this->setItemAlias($page, 'page', $this->alias);
$this->setItemImages($page, 'page', $this->image);
$this->setItemTranslation($page, 'page', $this->translation_entity);
if (!empty($page['images'])) {
foreach ($page['images'] as &$file) {
$this->setItemTranslation($file, 'file', $this->translation_entity);
}
}
$page['author'] = isset($user['email']) ? $user['email'] : $this->text('Unknown');
} | Prepares an array of page data
@param array $page | entailment |
protected function submitEditPage()
{
if ($this->isPosted('delete')) {
$this->deletePage();
} else if ($this->isPosted('save') && $this->validateEditPage()) {
$this->deleteImagesPage();
if (isset($this->data_page['page_id'])) {
$this->updatePage();
} else {
$this->addPage();
}
}
} | Handles a submitted page | entailment |
protected function deleteImagesPage()
{
$this->controlAccess('page_edit');
$file_ids = $this->getPosted('delete_images', array(), true, 'array');
return $this->image->delete($file_ids);
} | Delete page images
@return boolean | entailment |
protected function validateEditPage()
{
$this->setSubmitted('page', null, false);
$this->setSubmitted('form', true);
$this->setSubmitted('update', $this->data_page);
$this->setSubmittedBool('status');
$this->setSubmittedBool('blog_post');
if (empty($this->data_page['page_id'])) {
$this->setSubmitted('user_id', $this->uid);
}
$this->validateComponent('page');
return !$this->hasErrors();
} | Validates a submitted page
@return bool | entailment |
protected function deletePage()
{
$this->controlAccess('page_delete');
if ($this->page->delete($this->data_page['page_id'])) {
$this->redirect('admin/content/page', $this->text('Page has been deleted'), 'success');
}
$this->redirect('', $this->text('Page has not been deleted'), 'warning');
} | Deletes a page | entailment |
protected function updatePage()
{
$this->controlAccess('page_edit');
if ($this->page->update($this->data_page['page_id'], $this->getSubmitted())) {
$this->redirect('admin/content/page', $this->text('Page has been updated'), 'success');
}
$this->redirect('', $this->text('Page has not been updated'), 'warning');
} | Updates a page | entailment |
protected function addPage()
{
$this->controlAccess('page_add');
if ($this->page->add($this->getSubmitted())) {
$this->redirect('admin/content/page', $this->text('Page has been added'), 'success');
}
$this->redirect('', $this->text('Page has not been added'), 'warning');
} | Adds a new page | entailment |
protected function setDataImagesEditPage()
{
$options = array(
'entity' => 'page',
'images' => $this->getData('page.images', array())
);
$this->setItemThumb($options, $this->image);
$this->setData('attached_images', $this->getWidgetImages($this->language, $options));
} | Adds images on the page edit form | entailment |
protected function setDataCategoriesEditPage()
{
$op = array('store_id' => $this->getData('page.store_id', $this->store->getDefault()));
$categories = $this->getCategoryOptionsByStore($this->category, $this->category_group, $op);
$this->setData('categories', $categories);
} | Adds list of categories on the page edit form | entailment |
protected function setTitleEditPage()
{
if (isset($this->data_page['page_id'])) {
$title = $this->text('Edit %name', array('%name' => $this->data_page['title']));
} else {
$title = $this->text('Add page');
}
$this->setTitle($title);
} | Sets titles on the page edit | entailment |
protected function setBreadcrumbEditPage()
{
$breadcrumbs = array();
$breadcrumbs[] = array(
'url' => $this->url('admin'),
'text' => $this->text('Dashboard')
);
$breadcrumbs[] = array(
'text' => $this->text('Pages'),
'url' => $this->url('admin/content/page')
);
$this->setBreadcrumbs($breadcrumbs);
} | Sets breadcrumbs on the page edit | entailment |
public function addIndex($text, $entity, $entity_id, $language)
{
$values = array(
'text' => $text,
'entity' => $entity,
'language' => $language,
'entity_id' => $entity_id
);
return (bool) $this->db->insert('search_index', $values);
} | Adds an item to the search index
@param string $text
@param string $entity
@param integer $entity_id
@param string $language
@return boolean | entailment |
public function deleteIndex($entity, $entity_id, $language)
{
$values = array(
'entity' => $entity,
'language' => $language,
'entity_id' => $entity_id
);
return (bool) $this->db->delete('search_index', $values);
} | Deletes an item from the search index
@param string $entity
@param integer $entity_id
@param string $language
@return boolean | entailment |
public function setIndex($text, $entity, $entity_id, $language)
{
$this->deleteIndex($entity, $entity_id, $language);
if (empty($text)) {
return false;
}
return $this->addIndex($text, $entity, $entity_id, $language);
} | Sets an item to the search index
@param string $text
@param string $entity
@param integer $entity_id
@param string $language
@return boolean | entailment |
public function index($handler_id, $data)
{
$result = null;
$this->hook->attach('search.index', $handler_id, $data, $result, $this);
if (isset($result)) {
return $result;
}
return $this->callHandler($handler_id, 'index', array($data, $this));
} | Indexes an item
@param string $handler_id
@param array|string $data
@return mixed | entailment |
public function search($handler_id, $query, array $options = array())
{
if (!isset($options['language'])) {
$options['language'] = 'und';
}
$result = null;
$this->hook->attach('search', $handler_id, $query, $options, $result, $this);
if (isset($result)) {
return $result;
}
$filtered = $this->filterStopwords($query, $options['language']);
if (empty($filtered)) {
return null;
}
return $this->callHandler($handler_id, 'search', array($filtered, $options, $this));
} | Returns an array of items found for the search query
@param string $handler_id
@param string $query
@param array $options
@return mixed | entailment |
public function callHandler($handler_id, $method, array $args)
{
try {
$handlers = $this->getHandlers();
return Handler::call($handlers, $handler_id, $method, $args);
} catch (Exception $ex) {
return null;
}
} | Calls a search handler
@param string $handler_id
@param string $method
@param array $args
@return mixed | entailment |
public function getSnippet(array $data, $language)
{
$parts = array();
if (isset($data['title'])) {
// Repeat title twice to make it more important
$parts = array($data['title'], $data['title']);
}
if (isset($data['description'])) {
$parts[] = strip_tags($data['description']);
}
$snippet = $this->filterStopwords(implode(' ', $parts), $language);
$this->hook->attach('search.index.snippet', $data, $language, $snippet);
return $snippet;
} | Returns a text string to be saved in the index table
@param array $data
@param string $language
@return string | entailment |
public function getHandlers()
{
$handlers = &gplcart_static('search.handlers');
if (isset($handlers)) {
return $handlers;
}
$handlers = $this->getDefaultHandlers();
$this->hook->attach('search.handlers', $handlers, $this);
return $handlers;
} | Returns an array of handlers
@return array | entailment |
public function filterStopwords($string, $language)
{
$prepared = trim(strip_tags($string));
if ($prepared === '') {
return '';
}
$stopwords = array();
$path = GC_DIR_PRIVATE . "/stopwords/$language.txt";
if (is_readable($path)) {
$stopwords = array_map('trim', file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
}
return implode(' ', array_diff(explode(' ', $prepared), $stopwords));
} | Filters out stop-words for a given language
@param string $string
@param string $language
@return string | entailment |
protected function parseItem(string $itemName, ServerRequestInterface $request, bool $isSingle = false) : string
{
$item = $this->settings[$itemName];
// we allow callables to be set (along with strings) so we can vary things upon requests.
if (true === is_callable($item)) {
// all callbacks are made with the request as the second parameter.
$item = call_user_func($item, $request);
}
// if it is a boolean, we may as well return.
if (false === $item || null === $item) {
return '';
} elseif (true === $item) {
throw new \InvalidArgumentException('Cannot have true as a setting for '.$itemName);
}
// if it is a string, convert it into an array based on position of commas - but trim excess white spaces.
if (true === is_string($item)) {
$item = array_map('trim', explode(',', (string) $item));
}
// are we expecting a single item to be returned?
if (true === $isSingle) {
// if we are, and it is an int, return it as a string for type casting
if (true === is_int($item)) {
return (string) $item;
} elseif (count($item) === 1) {
// if we have a single item, return it.
return (string) $item[0];
} else {
throw new \InvalidArgumentException('Only expected a single string, int or bool');
}
}
// we always want to work on arrays
// explode the string and trim it.
if (false === is_array($item)) {
$item = array_map('trim', explode(',', (string) $item));
}
// if it is an array, we want to return a comma space separated list
$item = implode(', ', $item);
// return the string setting.
return $item;
} | Parse an item from string/int/callable/array to an expected value.
Generic used function for quite a few possible configuration settings.
@param string $itemName Which settings item are we accessing?.
@param ServerRequestInterface $request What is the request object? (for callables).
@param boolean $isSingle Are we expecting a single string/int as a return value.
@throws \InvalidArgumentException If the item is invalid.
@return string | entailment |
protected function parseAllowCredentials(ServerRequestInterface $request) : bool
{
// read in the current setting
$item = $this->settings['allowCredentials'];
// we allow callables to be set (along with strings) so we can vary things upon requests.
if (true === is_callable($item)) {
// all callbacks are made with the request as the second parameter.
$item = call_user_func($item, $request);
}
// if the credentials are still not a boolean, abort.
if (false === is_bool($item)) {
throw new \InvalidArgumentException('allowCredentials should be a boolean value');
}
// return the boolean credentials setting
return $item;
} | Parse the allow credentials setting.
@param ServerRequestInterface $request What is the request object? (for callables).
@throws \InvalidArgumentException If the item is missing from settings or is invalid.
@return boolean | entailment |
protected function parseMaxAge(ServerRequestInterface $request) : int
{
$item = $this->settings['maxAge'];
// we allow callables to be set (along with strings) so we can vary things upon requests.
if (true === is_callable($item)) {
// all callbacks are made with the request as the second parameter.
$item = call_user_func($item, $request);
}
// maxAge needs to be an int - if it isn't, throw an exception.
if (false === is_int($item)) {
throw new \InvalidArgumentException('maxAge should be an int value');
}
// if it is less than zero, reject it as "faulty"
if ($item < 0) {
throw new \InvalidArgumentException('maxAge should be 0 or more');
}
// return our integer maximum age to cache.
return $item;
} | Parse the maxAge setting.
@param ServerRequestInterface $request What is the request object? (for callables).
@throws \InvalidArgumentException If the item is missing from settings or is invalid.
@return integer | entailment |
protected function parseOrigin(ServerRequestInterface $request, array &$allowedOrigins = []) : string
{
// read the client provided origin header
$origin = $request->getHeaderLine('origin');
// if it isn't a string or is empty, the return as we will not have a matching
// origin setting.
if (false === is_string($origin) || '' === $origin) {
$this->addLog('Origin is empty or is not a string');
return '';
}
$this->addLog('Processing origin of "'.$origin.'"');
// lowercase the user provided origin for comparison purposes.
$origin = strtolower($origin);
$parsed = parse_url($origin);
$originHost = $origin;
if (true === is_array($parsed)) {
if (true === isset($parsed['host'])) {
$this->addLog('Parsed a hostname from origin: '.$parsed['host']);
$originHost = $parsed['host'];
}
} else {
$parsed = [];
}
// read the current origin setting
$originSetting = $this->settings['origin'];
// see if this is a callback
if (true === is_callable($originSetting)) {
// all callbacks are made with the request as the second parameter.
$this->addLog('Origin server request is being passed to callback');
$originSetting = call_user_func($originSetting, $request);
}
// set a dummy "matched with" setting
$matched = '';
// if it is an array (either set via configuration or returned via the call
// back), look through them.
if (true === is_array($originSetting)) {
$this->addLog('Iterating through Origin array');
foreach ($originSetting as $item) {
$allowedOrigins[] = $item;
// see if the origin matches (the parseOriginMatch function supports
// wildcards)
$matched = $this->parseOriginMatch($item, $originHost);
// if anything else but '' was returned, then we have a valid match.
if ('' !== $matched) {
$this->addLog('Iterator found a matched origin of '.$matched);
$matched = $this->addProtocolPortIfNeeded($matched, $parsed);
return $matched;
}
}
}
// if we've got this far, than nothing so far has matched, our last attempt
// is to try to match it as a string (if applicable)
if ('' === $matched && true === is_string($originSetting)) {
$this->addLog('Attempting to match origin as string');
$allowedOrigins[] = $originSetting;
$matched = $this->parseOriginMatch($originSetting, $originHost);
}
// return the matched setting (may be '' to indicate nothing matched)
$matched = $this->addProtocolPortIfNeeded($matched, $parsed);
return $matched;
} | Parse the origin setting using wildcards where necessary.
Can return * for "all hosts", '' for "no origin/do not allow" or a string/hostname.
@param ServerRequestInterface $request The server request with the origin header.
@param array|callable $allowedOrigins The returned list of allowed origins found.
@return string | entailment |
protected function addProtocolPortIfNeeded(string $matched, array $parsed) : string
{
if ('' === $matched || '*' === $matched) {
$return = $matched;
return $return;
}
$protocol = 'https://';
$port = 0;
if (true === isset($parsed['scheme'])) {
$this->addLog('Parsed a protocol from origin: '.$parsed['scheme']);
$protocol = $parsed['scheme'].'://';
} else {
$this->addLog('Unable to parse protocol/scheme from origin');
}
if (true === isset($parsed['port'])) {
$this->addLog('Parsed a port from origin: '.$parsed['port']);
$port = (int) $parsed['port'];
} else {
$this->addLog('Unable to parse port from origin');
}
if (0 === $port) {
if ('https://' === $protocol) {
$port = 443;
} else {
$port = 80;
}
}
if (('http://' === $protocol && 80 === $port) || ('https://' === $protocol && 443 === $port)) {
$return = $protocol.$matched;
} else {
$return = $protocol.$matched.':'.$port;
}
return $return;
} | Returns the protocol if needed.
@param string $matched The matched host.
@param array $parsed The results of parse_url.
@return string | entailment |
protected function parseOriginMatch(string $item, string $origin) :string
{
$this->addLog('Checking configuration origin of "'.$item.'" against user "'.$origin.'"');
if ('' === $item || '*' === $item) {
$this->addLog('Origin is either an empty string or wildcarded star. Returning '.$item);
return $item;
}
// host names are case insensitive, so lower case it.
$item = strtolower($item);
// if the item does NOT contain a star, make a straight comparison
if (false === strpos($item, '*')) {
if ($item === $origin) {
// if we have a match, then return.
$this->addLog('Origin is an exact case insensitive match');
return $origin;
}
} else {
// item contains one or more stars/wildcards
// ensure we have no preg characters in the item
$quoted = preg_quote($item, '/');
// replace the preg_quote escaped star with .*
$quoted = str_replace('\*', '.*', $quoted);
// see if we have a preg_match, and, if we do, return it.
if (1 === preg_match('/^'.$quoted.'$/', $origin)) {
$this->addLog('Wildcarded origin match with '.$origin);
return $origin;
}
}
// if nothing is matched, then return an empty string.
$this->addLog('Unable to match "'.$item.'" against user "'.$origin.'"');
return '';
} | Check to see if an origin string matches an item (wildcarded or not).
@param string $item The string (possible * wildcarded) to compare against.
@param string $origin The origin to check.
@return string The matching origin (can be *) or '' for empty/not matched | entailment |
public function indexProduct($product_id)
{
$this->setProduct($product_id);
$this->setMetaIndexProduct();
$this->setTitleIndexProduct();
$this->setBreadcrumbIndexProduct();
$this->setHtmlFilterIndexProduct();
$this->setData('product', $this->data_product);
$this->setDataSummaryIndexProduct();
$this->setDataImagesIndexProduct();
$this->setDataCartFormIndexProduct();
$this->setDataRatingWidgetIndexProduct();
$this->setDataDescriptionIndexProduct();
$this->setDataAttributesIndexProduct();
$this->setDataReviewsIndexProduct();
$this->setDataRecentIndexProduct();
$this->setDataRelatedIndexProduct();
$this->setDataBundledIndexProduct();
$this->setJsIndexProduct();
$this->outputIndexProduct();
} | Displays the product page
@param integer $product_id | entailment |
protected function setDataSummaryIndexProduct()
{
$summary = '';
if (!empty($this->data_product['description'])) {
$exploded = $this->explodeText($this->data_product['description']);
$summary = strip_tags($exploded[0]);
}
$this->setData('summary', $summary);
} | Sets the description summary on the product page | entailment |
protected function setDataCartFormIndexProduct()
{
$data = array(
'product' => $this->data_product,
'share' => $this->getWidgetShare()
);
$this->setData('cart_form', $this->render('cart/add', $data, true));
} | Sets the "Add to cart" form | entailment |
protected function setDataRatingWidgetIndexProduct()
{
$data = array(
'product' => $this->data_product,
'rating' => $this->rating->getByProduct($this->data_product['product_id'])
);
$this->setData('rating', $this->render('common/rating/static', $data));
} | Sets the product rating widget | entailment |
protected function setDataDescriptionIndexProduct()
{
$description = $this->data_product['description'];
if (!empty($description)) {
$exploded = $this->explodeText($description);
if (!empty($exploded[1])) {
$description = $exploded[1];
}
}
$rendered = $this->render('product/description', array('description' => $description));
$this->setData('description', $rendered);
} | Sets the product description | entailment |
protected function setDataReviewsIndexProduct()
{
if ($this->config('review_enabled', 1) && !empty($this->data_product['total_reviews'])) {
$pager_options = array(
'key' => 'rep',
'total' => $this->data_product['total_reviews'],
'limit' => (int) $this->config('review_limit', 5)
);
$pager = $this->getPager($pager_options);
$data = array(
'product' => $this->data_product,
'pager' => $pager['rendered'],
'reviews' => $this->getReviewsProduct($pager['limit'])
);
$this->setData('reviews', $this->render('review/list', $data, true));
}
} | Sets the product reviews | entailment |
protected function setDataRecentIndexProduct()
{
$products = $this->getRecentProduct();
if (!empty($products)) {
$pager_options = array(
'key' => 'pwp',
'total' => count($products),
'limit' => $this->config('product_view_pager_limit', 4)
);
$pager = $this->getPager($pager_options);
if (!empty($pager['limit'])) {
list($from, $to) = $pager['limit'];
$products = array_slice($products, $from, $to, true);
}
$data = array('pager' => $pager['rendered'], 'products' => $products);
$this->setData('recent', $this->render('product/recent', $data));
}
} | Sets the recent products block | entailment |
protected function setDataRelatedIndexProduct()
{
$products = $this->getRelatedProduct();
if (!empty($products)) {
$pager_options = array(
'key' => 'rlp',
'total' => count($products),
'limit' => $this->config('related_pager_limit', 4)
);
$pager = $this->getPager($pager_options);
if (!empty($pager['limit'])) {
list($from, $to) = $pager['limit'];
$products = array_slice($products, $from, $to);
}
$data = array(
'products' => $products,
'pager' => $pager['rendered']
);
$this->setData('related', $this->render('product/related', $data));
}
} | Sets the related products | entailment |
protected function prepareReviewsProduct(array &$reviews)
{
if (!empty($reviews)) {
$users = array();
foreach ($reviews as $review) {
$users[] = $review['user_id'];
}
$ratings = null;
if (!empty($users)) {
$ratings = $this->rating->getByUser($this->data_product['product_id'], $users);
}
foreach ($reviews as &$review) {
$rating = array('rating' => 0);
if (isset($ratings[$review['user_id']]['rating'])) {
$rating['rating'] = $ratings[$review['user_id']]['rating'];
}
$review['rating'] = $rating['rating'];
$review['rating_formatted'] = $this->render('common/rating/static', array('rating' => $rating));
}
}
} | Prepare an array of reviews
@param array $reviews | entailment |
protected function getReviewsProduct(array $limit)
{
$options = array(
'status' => 1,
'limit' => $limit,
'user_status' => 1,
'sort' => 'created',
'order' => 'desc',
'product_id' => $this->data_product['product_id']
);
$options += $this->query;
$list = (array) $this->review->getList($options);
$this->prepareReviewsProduct($list);
return $list;
} | Returns an array of reviews for the product
@param array $limit
@return array | entailment |
protected function setBreadcrumbIndexProduct()
{
$breadcrumbs = array();
$breadcrumbs[] = array(
'url' => $this->url('/'),
'text' => $this->text('Home')
);
$categories = $this->getCategorytBreadcrumbsProduct($this->data_product['category_id']);
$this->setBreadcrumbs(array_merge($breadcrumbs, $categories));
} | Sets breadcrumbs on the product page | entailment |
protected function buildCategoryBreadcrumbsProduct($category_id, array &$breadcrumbs)
{
if (!empty($this->data_categories[$category_id]['parents'])) {
$category = $this->data_categories[$category_id];
$parent = reset($category['parents']);
$url = empty($category['alias']) ? "category/$category_id" : $category['alias'];
$breadcrumb = array(
'url' => $this->url($url),
'text' => $category['title']
);
array_unshift($breadcrumbs, $breadcrumb);
$this->buildCategoryBreadcrumbsProduct($parent, $breadcrumbs);
}
} | Builds an array of breadcrumbs containing all parent categories
@param integer $category_id
@param array $breadcrumbs | entailment |
protected function getTotalReviewsProduct(array $product)
{
$options = array(
'status' => 1,
'count' => true,
'user_status' => 1,
'product_id' => $product['product_id']
);
return (int) $this->review->getList($options);
} | Returns a total number of reviews for the product
@param array $product
@return integer | entailment |
protected function setProduct($product_id)
{
$this->data_product = $this->product->get($product_id);
if (empty($this->data_product)) {
$this->outputHttpStatus(404);
}
$this->controlAccessProduct();
$this->prepareProduct($this->data_product);
} | Set a product data
@param integer $product_id | entailment |
protected function controlAccessProduct()
{
if (empty($this->data_product['store_id']) || $this->data_product['store_id'] != $this->store_id) {
$this->outputHttpStatus(403);
}
if (empty($this->data_product['status']) && !$this->access('product')) {
$this->outputHttpStatus(403);
}
} | Controls access to the product | entailment |
protected function prepareProduct(array &$product)
{
$selected = $this->getSelectedCombinationProduct($product);
$this->unshiftSelectedImageProduct($selected, $product);
$this->setItemImages($product, 'product', $this->image);
$this->setItemThumbProduct($product, $this->image);
$this->setItemProductInComparison($product, $this->product_compare);
$this->setItemProductBundle($product, $this->product, $this->image);
$this->setItemProductInWishlist($product, $this->wishlist);
$this->setItemPriceCalculated($selected, $this->product);
$this->setItemPriceFormatted($selected, $this->price, $this->current_currency);
$product['selected_combination'] = $selected;
$product['total_reviews'] = $this->getTotalReviewsProduct($product);
$this->setItemProductFields($product, $this->image, $this->product_class);
} | Prepare an array of product data
@param array $product | entailment |
protected function getSelectedCombinationProduct(array $product)
{
$field_value_ids = array();
if (!empty($product['default_field_values'])) {
$field_value_ids = $product['default_field_values'];
}
$selected = $this->sku->selectCombination($product, $field_value_ids);
$selected += $product;
return $selected;
} | Returns selected product combination
@param array $product
@return array | entailment |
protected function unshiftSelectedImageProduct($selected, &$product)
{
if (isset($selected['combination']['file_id']) && isset($product['images'][$selected['combination']['file_id']])) {
$image = $product['images'][$selected['combination']['file_id']];
unset($product['images'][$selected['combination']['file_id']]);
$product['images'] = array($image['file_id'] => $image) + $product['images'];
}
} | Put default selected image on the first position
@param array $selected
@param array $product
@todo Replace with a trait | entailment |
protected function getRelatedProduct()
{
$options = array(
'status' => 1,
'store_id' => $this->store_id,
'product_id' => $this->data_product['product_id'],
'limit' => array(0, $this->config('related_limit', 12))
);
$product_ids = (array) $this->product->getRelated($options);
$products = array();
if (!empty($product_ids)) {
$products = (array) $this->product->getList(array('product_id' => $product_ids));
}
$this->prepareEntityItems($products, array('entity' => 'product'));
return $products;
} | Returns an array of related products
@return array | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.