本文整理汇总了PHP中Cache::isStored方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::isStored方法的具体用法?PHP Cache::isStored怎么用?PHP Cache::isStored使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::isStored方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($id = null, $enable_hook = true)
{
$this->class_name = get_class($this);
if (!Object::$db) {
Object::$db = Db::getInstance();
}
self::$is_cache_enabled = defined('OBJECT_CACHE_ENABLE') ? OBJECT_CACHE_ENABLE : false;
if (isset($id) && Validate::isUnsignedId($id)) {
$cache_id = $this->class_name . self::CACHE_PREFIX_MODEL . (int) $id;
if (!Cache::isStored($cache_id)) {
$sql = new DbQuery();
$sql->from($this->def['table'], 'a');
$sql->where('a.' . $this->def['primary'] . '=' . (int) $id);
if ($object_datas = Object::$db->getRow($sql)) {
Cache::store($cache_id, $object_datas);
}
} else {
$object_datas = Cache::retrieve($cache_id);
}
if ($object_datas) {
$this->id = (int) $id;
foreach ($object_datas as $key => $value) {
if (array_key_exists($key, $this)) {
$this->{$key} = $value;
}
}
}
if ($enable_hook && method_exists($this, 'extraConstruct')) {
$this->extraConstruct();
}
}
}
示例2: load
/**
* Load ObjectModel
* @param $id
* @param $id_lang
* @param $entity ObjectModel
* @param $entity_defs
* @param $id_shop
* @param $should_cache_objects
* @throws PrestaShopDatabaseException
*/
public function load($id, $id_lang, $entity, $entity_defs, $id_shop, $should_cache_objects)
{
// Load object from database if object id is present
$cache_id = 'objectmodel_' . $entity_defs['classname'] . '_' . (int) $id . '_' . (int) $id_shop . '_' . (int) $id_lang;
if (!$should_cache_objects || !Cache::isStored($cache_id)) {
$sql = new DbQuery();
$sql->from($entity_defs['table'], 'a');
$sql->where('a.`' . bqSQL($entity_defs['primary']) . '` = ' . (int) $id);
// Get lang informations
if ($id_lang && isset($entity_defs['multilang']) && $entity_defs['multilang']) {
$sql->leftJoin($entity_defs['table'] . '_lang', 'b', 'a.`' . bqSQL($entity_defs['primary']) . '` = b.`' . bqSQL($entity_defs['primary']) . '` AND b.`id_lang` = ' . (int) $id_lang);
if ($id_shop && !empty($entity_defs['multilang_shop'])) {
$sql->where('b.`id_shop` = ' . (int) $id_shop);
}
}
// Get shop informations
if (Shop::isTableAssociated($entity_defs['table'])) {
$sql->leftJoin($entity_defs['table'] . '_shop', 'c', 'a.`' . bqSQL($entity_defs['primary']) . '` = c.`' . bqSQL($entity_defs['primary']) . '` AND c.`id_shop` = ' . (int) $id_shop);
}
if ($object_datas = Db::getInstance()->getRow($sql)) {
if (!$id_lang && isset($entity_defs['multilang']) && $entity_defs['multilang']) {
$sql = 'SELECT *
FROM `' . bqSQL(_DB_PREFIX_ . $entity_defs['table']) . '_lang`
WHERE `' . bqSQL($entity_defs['primary']) . '` = ' . (int) $id . ($id_shop && $entity->isLangMultishop() ? ' AND `id_shop` = ' . (int) $id_shop : '');
if ($object_datas_lang = Db::getInstance()->executeS($sql)) {
foreach ($object_datas_lang as $row) {
foreach ($row as $key => $value) {
if ($key != $entity_defs['primary'] && array_key_exists($key, $entity)) {
if (!isset($object_datas[$key]) || !is_array($object_datas[$key])) {
$object_datas[$key] = array();
}
$object_datas[$key][$row['id_lang']] = $value;
}
}
}
}
}
$entity->id = (int) $id;
foreach ($object_datas as $key => $value) {
if (array_key_exists($key, $entity)) {
$entity->{$key} = $value;
} else {
unset($object_datas[$key]);
}
}
if ($should_cache_objects) {
Cache::store($cache_id, $object_datas);
}
}
} else {
$object_datas = Cache::retrieve($cache_id);
if ($object_datas) {
$entity->id = (int) $id;
foreach ($object_datas as $key => $value) {
$entity->{$key} = $value;
}
}
}
}
示例3: isTaxInUse
/**
* @param int $id_tax
* @return bool
*/
public static function isTaxInUse($id_tax)
{
$cache_id = 'TaxRule::isTaxInUse_' . (int) $id_tax;
if (!Cache::isStored($cache_id)) {
$result = (int) Db::getInstance()->getValue('SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'tax_rule` WHERE `id_tax` = ' . (int) $id_tax);
Cache::store($cache_id, $result);
return $result;
}
return Cache::retrieve($cache_id);
}
示例4: getOrderStates
/**
* Get all available order statuses
*
* @param integer $id_lang Language id for status name
* @return array Order statuses
*/
public static function getOrderStates($id_lang)
{
$cache_id = 'OrderState::getOrderStates_' . (int) $id_lang;
if (!Cache::isStored($cache_id)) {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `' . _DB_PREFIX_ . 'order_state` os
LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = ' . (int) $id_lang . ')
WHERE deleted = 0
ORDER BY `name` ASC');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
}
示例5: getZones
/**
* Get all available geographical zones
*
* @param bool $active
* @return array Zones
*/
public static function getZones($active = false)
{
$cache_id = 'Zone::getZones_' . (bool) $active;
if (!Cache::isStored($cache_id)) {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `' . _DB_PREFIX_ . 'zone`
' . ($active ? 'WHERE active = 1' : '') . '
ORDER BY `name` ASC
');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
}
示例6: getTaxCalculator
/**
* Return the tax calculator associated to this address
*
* @return TaxCalculator
*/
public function getTaxCalculator()
{
static $tax_enabled = null;
if (isset($this->tax_calculator)) {
return $this->tax_calculator;
}
if ($tax_enabled === null) {
$tax_enabled = $this->configurationManager->get('PS_TAX');
}
if (!$tax_enabled) {
return new TaxCalculator(array());
}
$taxes = array();
$postcode = 0;
if (!empty($this->address->postcode)) {
$postcode = $this->address->postcode;
}
$cache_id = (int) $this->address->id_country . '-' . (int) $this->address->id_state . '-' . $postcode . '-' . (int) $this->type;
if (!Cache::isStored($cache_id)) {
$rows = Db::getInstance()->executeS('
SELECT tr.*
FROM `' . _DB_PREFIX_ . 'tax_rule` tr
JOIN `' . _DB_PREFIX_ . 'tax_rules_group` trg ON (tr.`id_tax_rules_group` = trg.`id_tax_rules_group`)
WHERE trg.`active` = 1
AND tr.`id_country` = ' . (int) $this->address->id_country . '
AND tr.`id_tax_rules_group` = ' . (int) $this->type . '
AND tr.`id_state` IN (0, ' . (int) $this->address->id_state . ')
AND (\'' . pSQL($postcode) . '\' BETWEEN tr.`zipcode_from` AND tr.`zipcode_to`
OR (tr.`zipcode_to` = 0 AND tr.`zipcode_from` IN(0, \'' . pSQL($postcode) . '\')))
ORDER BY tr.`zipcode_from` DESC, tr.`zipcode_to` DESC, tr.`id_state` DESC, tr.`id_country` DESC');
$behavior = 0;
$first_row = true;
foreach ($rows as $row) {
$tax = new Tax((int) $row['id_tax']);
$taxes[] = $tax;
// the applied behavior correspond to the most specific rules
if ($first_row) {
$behavior = $row['behavior'];
$first_row = false;
}
if ($row['behavior'] == 0) {
break;
}
}
$result = new TaxCalculator($taxes, $behavior);
Cache::store($cache_id, $result);
return $result;
}
return Cache::retrieve($cache_id);
}
示例7: getIdByName
/**
* Get a state id with its name
*
* @param string $id_state Country ID
* @return integer state id
*/
public static function getIdByName($state)
{
if (empty($state)) {
return false;
}
$cache_id = 'State::getNameById_' . pSQL($state);
if (!Cache::isStored($cache_id)) {
$result = (int) Db::getInstance()->getValue('
SELECT `id_state`
FROM `' . _DB_PREFIX_ . 'state`
WHERE `name` LIKE \'' . pSQL($state) . '\'
');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
}
示例8: setLastVisitedCategory
public function setLastVisitedCategory()
{
$cache_id = 'pspagebuilder::setLastVisitedCategory';
$context = Context::getContext();
if (!Cache::isStored($cache_id)) {
if (method_exists($context->controller, 'getCategory') && ($category = $context->controller->getCategory())) {
$context->cookie->last_visited_category = $category->id;
} elseif (method_exists($context->controller, 'getProduct') && ($product = $context->controller->getProduct())) {
if (!isset($context->cookie->last_visited_category) || !Product::idIsOnCategoryId($product->id, array(array('id_category' => $context->cookie->last_visited_category))) || !Category::inShopStatic($context->cookie->last_visited_category, $context->shop)) {
$context->cookie->last_visited_category = (int) $product->id_category_default;
}
}
Cache::store($cache_id, $context->cookie->last_visited_category);
}
return Cache::retrieve($cache_id);
}
示例9: getAddresses
/**
* Return customer addresses
* Override method with default Prestashop Method, To don't show the Receiver address to Custommer/ Sender
* @param integer $id_lang Language ID
* @param bool $ship2myid_flag flag to show the address
* @return array Addresses
*/
public function getAddresses($id_lang, $ship2myid_flag = true)
{
$share_order = (bool) Context::getContext()->shop->getGroup()->share_order;
$cache_id = 'Customer::getAddresses' . (int) $this->id . '-' . (int) $id_lang . '-' . $share_order;
if (!Cache::isStored($cache_id)) {
$sql = 'SELECT DISTINCT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso
FROM `' . _DB_PREFIX_ . 'address` a
LEFT JOIN `' . _DB_PREFIX_ . 'country` c ON (a.`id_country` = c.`id_country`)
LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (c.`id_country` = cl.`id_country`)
LEFT JOIN `' . _DB_PREFIX_ . 'state` s ON (s.`id_state` = a.`id_state`)
' . ($share_order ? '' : Shop::addSqlAssociation('country', 'c')) . '
WHERE `id_lang` = ' . (int) $id_lang . ' AND `id_customer` = ' . (int) $this->id . ' AND a.`deleted` = 0';
//echo $ship2myid_flag.'hii';
if ($ship2myid_flag) {
$sql .= ' AND ( ( LOWER(alias ) NOT LIKE "ship2myid-%") AND (LOWER(alias) NOT LIKE "shiptomyid-%" ) ) ';
}
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
}
示例10: isLoggedBack
/**
* Check employee informations saved into cookie and return employee validity
*
* @return bool employee validity
*/
public function isLoggedBack()
{
if (!Cache::isStored('isLoggedBack' . $this->id)) {
/* Employee is valid only if it can be load and if cookie password is the same as database one */
$result = $this->id && Validate::isUnsignedId($this->id) && Employee::checkPassword($this->id, Context::getContext()->cookie->passwd) && (!isset(Context::getContext()->cookie->remote_addr) || Context::getContext()->cookie->remote_addr == ip2long(Tools::getRemoteAddr()) || !Configuration::get('PS_COOKIE_CHECKIP'));
Cache::store('isLoggedBack' . $this->id, $result);
return $result;
}
return Cache::retrieve('isLoggedBack' . $this->id);
}
示例11: getIdByName
/**
* Get a city id with its name
*
* @param string $id_state Country ID
* @return int city id
*/
public static function getIdByName($city)
{
if (empty($city)) {
return false;
}
$cache_id = 'City::getIdByName_' . pSQL($city);
if (!Cache::isStored($cache_id)) {
$result = (int) Db::getInstance()->getValue('
SELECT `id_city`
FROM `' . _DB_PREFIX_ . 'city`
WHERE `name` = \'' . pSQL($city) . '\'
');
Cache::store($cache_id, $result);
return $result;
}
return Cache::retrieve($cache_id);
}
示例12: getAvailableCarrierList
/**
* For a given {product, warehouse}, gets the carrier available
*
* @since 1.5.0
*
* @param Product $product The id of the product, or an array with at least the package size and weight
* @param int $id_warehouse Warehouse ID
* @param int $id_address_delivery Delivery Address ID
* @param int $id_shop Shop ID
* @param Cart $cart Cart object
* @param array &$error contain an error message if an error occurs
*
* @return array Available Carriers
* @throws PrestaShopDatabaseException
*/
public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null, $cart = null, &$error = array())
{
static $ps_country_default = null;
if ($ps_country_default === null) {
$ps_country_default = Configuration::get('PS_COUNTRY_DEFAULT');
}
if (is_null($id_shop)) {
$id_shop = Context::getContext()->shop->id;
}
if (is_null($cart)) {
$cart = Context::getContext()->cart;
}
if (is_null($error) || !is_array($error)) {
$error = array();
}
$id_address = (int) (!is_null($id_address_delivery) && $id_address_delivery != 0 ? $id_address_delivery : $cart->id_address_delivery);
if ($id_address) {
$id_zone = Address::getZoneById($id_address);
// Check the country of the address is activated
if (!Address::isCountryActiveById($id_address)) {
return array();
}
} else {
$country = new Country($ps_country_default);
$id_zone = $country->id_zone;
}
// Does the product is linked with carriers?
$cache_id = 'Carrier::getAvailableCarrierList_' . (int) $product->id . '-' . (int) $id_shop;
if (!Cache::isStored($cache_id)) {
$query = new DbQuery();
$query->select('id_carrier');
$query->from('product_carrier', 'pc');
$query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0 AND c.active = 1');
$query->where('pc.id_product = ' . (int) $product->id);
$query->where('pc.id_shop = ' . (int) $id_shop);
$carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
Cache::store($cache_id, $carriers_for_product);
} else {
$carriers_for_product = Cache::retrieve($cache_id);
}
$carrier_list = array();
if (!empty($carriers_for_product)) {
//the product is linked with carriers
foreach ($carriers_for_product as $carrier) {
//check if the linked carriers are available in current zone
if (Carrier::checkCarrierZone($carrier['id_carrier'], $id_zone)) {
$carrier_list[$carrier['id_carrier']] = $carrier['id_carrier'];
}
}
if (empty($carrier_list)) {
return array();
}
//no linked carrier are available for this zone
}
// The product is not directly linked with a carrier
// Get all the carriers linked to a warehouse
if ($id_warehouse) {
$warehouse = new Warehouse($id_warehouse);
$warehouse_carrier_list = $warehouse->getCarriers();
}
$available_carrier_list = array();
$cache_id = 'Carrier::getAvailableCarrierList_getCarriersForOrder_' . (int) $id_zone . '-' . (int) $cart->id;
if (!Cache::isStored($cache_id)) {
$customer = new Customer($cart->id_customer);
$carrier_error = array();
$carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups(), $cart, $carrier_error);
Cache::store($cache_id, array($carriers, $carrier_error));
} else {
list($carriers, $carrier_error) = Cache::retrieve($cache_id);
}
$error = array_merge($error, $carrier_error);
foreach ($carriers as $carrier) {
$available_carrier_list[$carrier['id_carrier']] = $carrier['id_carrier'];
}
if ($carrier_list) {
$carrier_list = array_intersect($available_carrier_list, $carrier_list);
} else {
$carrier_list = $available_carrier_list;
}
if (isset($warehouse_carrier_list)) {
$carrier_list = array_intersect($carrier_list, $warehouse_carrier_list);
}
$cart_quantity = 0;
$cart_weight = 0;
foreach ($cart->getProducts(false, false) as $cart_product) {
//.........这里部分代码省略.........
示例13: setNoMultishipping
/**
* Update products cart address delivery with the address delivery of the cart
*/
public function setNoMultishipping()
{
$emptyCache = false;
if (Configuration::get('PS_ALLOW_MULTISHIPPING')) {
// Upgrading quantities
$sql = 'SELECT sum(`quantity`) as quantity, id_product, id_product_attribute, count(*) as count
FROM `' . _DB_PREFIX_ . 'cart_product`
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_shop` = ' . (int) $this->id_shop . '
GROUP BY id_product, id_product_attribute
HAVING count > 1';
foreach (Db::getInstance()->executeS($sql) as $product) {
$sql = 'UPDATE `' . _DB_PREFIX_ . 'cart_product`
SET `quantity` = ' . $product['quantity'] . '
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_shop` = ' . (int) $this->id_shop . '
AND id_product = ' . $product['id_product'] . '
AND id_product_attribute = ' . $product['id_product_attribute'];
if (Db::getInstance()->execute($sql)) {
$emptyCache = true;
}
}
// Merging multiple lines
$sql = 'DELETE cp1
FROM `' . _DB_PREFIX_ . 'cart_product` cp1
INNER JOIN `' . _DB_PREFIX_ . 'cart_product` cp2
ON (
(cp1.id_cart = cp2.id_cart)
AND (cp1.id_product = cp2.id_product)
AND (cp1.id_product_attribute = cp2.id_product_attribute)
AND (cp1.id_address_delivery <> cp2.id_address_delivery)
AND (cp1.date_add > cp2.date_add)
)';
Db::getInstance()->execute($sql);
}
// Update delivery address for each product line
$sql = 'UPDATE `' . _DB_PREFIX_ . 'cart_product`
SET `id_address_delivery` = (
SELECT `id_address_delivery` FROM `' . _DB_PREFIX_ . 'cart`
WHERE `id_cart` = ' . (int) $this->id . ' AND `id_shop` = ' . (int) $this->id_shop . '
)
WHERE `id_cart` = ' . (int) $this->id . '
' . (Configuration::get('PS_ALLOW_MULTISHIPPING') ? ' AND `id_shop` = ' . (int) $this->id_shop : '');
$cache_id = 'Cart::setNoMultishipping' . (int) $this->id . '-' . (int) $this->id_shop;
if (!Cache::isStored($cache_id)) {
if ($result = (bool) Db::getInstance()->execute($sql)) {
$emptyCache = true;
}
Cache::store($cache_id, $result);
}
if (Customization::isFeatureActive()) {
Db::getInstance()->execute('
UPDATE `' . _DB_PREFIX_ . 'customization`
SET `id_address_delivery` = (
SELECT `id_address_delivery` FROM `' . _DB_PREFIX_ . 'cart`
WHERE `id_cart` = ' . (int) $this->id . '
)
WHERE `id_cart` = ' . (int) $this->id);
}
if ($emptyCache) {
$this->_products = null;
}
}
示例14: getDiscountsCustomer
public static function getDiscountsCustomer($id_customer, $id_cart_rule)
{
$cache_id = 'Order::getDiscountsCustomer_' . (int) $id_customer . '-' . (int) $id_cart_rule;
if (!Cache::isStored($cache_id)) {
$result = (int) Db::getInstance()->getValue('
SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'orders` o
LEFT JOIN ' . _DB_PREFIX_ . 'order_cart_rule ocr ON (ocr.id_order = o.id_order)
WHERE o.id_customer = ' . (int) $id_customer . '
AND ocr.id_cart_rule = ' . (int) $id_cart_rule);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
}
示例15: getCategoryMetas
/**
* Get category meta tags
*
* @since 1.5.0
* @param int $id_category
* @param int $id_lang
* @param string $page_name
* @return array
*/
public static function getCategoryMetas($id_category, $id_lang, $page_name, $title = '')
{
if (!empty($title)) {
$title = ' - ' . $title;
}
$page_number = (int) Tools::getValue('p');
$sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description`
FROM `' . _DB_PREFIX_ . 'category_lang` cl
WHERE cl.`id_lang` = ' . (int) $id_lang . '
AND cl.`id_category` = ' . (int) $id_category . Shop::addSqlRestrictionOnLang('cl');
$cache_id = 'Meta::getCategoryMetas' . (int) $id_category . '-' . (int) $id_lang;
if (!Cache::isStored($cache_id)) {
if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql)) {
if (empty($row['meta_description'])) {
$row['meta_description'] = strip_tags($row['description']);
}
// Paginate title
if (!empty($row['meta_title'])) {
$row['meta_title'] = $title . $row['meta_title'] . (!empty($page_number) ? ' (' . $page_number . ')' : '') . ' - ' . Configuration::get('PS_SHOP_NAME') . ' %city_name';
} else {
$row['meta_title'] = $row['name'] . (!empty($page_number) ? ' (' . $page_number . ')' : '') . ' - ' . Configuration::get('PS_SHOP_NAME') . ' %city_name';
}
if (!empty($title)) {
$row['meta_title'] = $title . (!empty($page_number) ? ' (' . $page_number . ')' : '') . ' - ' . Configuration::get('PS_SHOP_NAME') . ' %city_name';
}
$result = Meta::completeMetaTags($row, $row['name']);
} else {
$result = Meta::getHomeMetas($id_lang, $page_name);
}
Meta::getEgCeoWords('category', $id_category, $result);
$result = Meta::replaceCity($result);
//$row['meta_description'] = $result['description'];
$row = Meta::replaceCity($row);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
}