本文整理汇总了PHP中Shopp::cache_set方法的典型用法代码示例。如果您正苦于以下问题:PHP Shopp::cache_set方法的具体用法?PHP Shopp::cache_set怎么用?PHP Shopp::cache_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shopp
的用法示例。
在下文中一共展示了Shopp::cache_set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smart
public function smart(array $options = array())
{
$this->name = __('Customers also bought…', 'Shopp');
$this->controls = false;
$where = array("true=false");
$scope = array();
$Product = ShoppProduct();
$Order = ShoppOrder();
$Cart = $Order->Cart;
// Use the current product is available
if (!empty($Product->id)) {
$this->product = $Product;
}
// Or load a product specified
if (!empty($options['product'])) {
if ('recent-cartitem' == $options['product']) {
// Use most recently added item in the cart
$this->product = new ShoppProduct($Cart->added()->product);
} elseif (preg_match('/^[\\d+]$/', $options['product'])) {
// Load by specified id
$this->product = new ShoppProduct($options['product']);
} else {
$this->product = new ShoppProduct($options['product'], 'slug');
// Load by specified slug
}
}
if (empty($this->product->id)) {
$loading = compact('where');
$this->loading = array_merge($options, $loading);
return;
}
$this->name = Shopp::__('Customers that bought "%s" also bought…', $this->product->name);
$purchased = ShoppDatabaseObject::tablename(Purchased::$table);
$query = "SELECT p2,((psum - (sum1 * sum2 / n)) / sqrt((sum1sq - pow(sum1, 2.0) / n) * (sum2sq - pow(sum2, 2.0) / n))) AS r, n\n\t\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\t\tSELECT n1.product AS p1,n2.product AS p2,SUM(n1.quantity) AS sum1,SUM(n2.quantity) AS sum2,\n\t\t\t\t\t\t\t\t\t\tSUM(n1.quantity * n1.quantity) AS sum1sq,SUM(n2.quantity * n2.quantity) AS sum2sq,\n\t\t\t\t\t\t\t\t\t\tSUM(n1.quantity * n2.quantity) AS psum,COUNT(*) AS n\n\t\t\t\t\t\t\t\t\tFROM {$purchased} AS n1\n\t\t\t\t\t\t\t\t\tLEFT JOIN {$purchased} AS n2 ON n1.purchase = n2.purchase\n\t\t\t\t\t\t\t\t\tWHERE n1.product != n2.product\n\t\t\t\t\t\t\t\t\tGROUP BY n1.product,n2.product\n\t\t\t\t\t\t\t\t) AS step1\n\t\t\t\t\t\t\t\tORDER BY r DESC, n DESC";
$cachehash = 'alsobought_' . md5($query);
$cached = Shopp::cache_get($cachehash, 'shopp_collection_alsobought');
if ($cached) {
$matches = $cached;
} else {
$matches = sDB::query($query, 'array', 'col', 'p2');
Shopp::cache_set($cachehash, $matches, 'shopp_collection_alsobought', 14400);
//Expires in 4 hours
}
if (empty($matches)) {
$loading = compact('where');
$this->loading = array_merge($options, $loading);
return;
}
$where = array("p.id IN (" . join(',', $matches) . ")");
$loading = compact('columns', 'joins', 'where', 'groupby', 'order');
$this->loading = array_merge($options, $loading);
if (isset($options['controls']) && Shopp::str_true($options['controls'])) {
unset($this->controls);
}
}
示例2: loader
//.........这里部分代码省略.........
$ps = ShoppDatabaseObject::tablename(ProductSummary::$table);
$orderdirs = array('asc', 'desc');
if (in_array($order, $orderdirs)) {
$orderd = strtolower($order);
} else {
$orderd = 'asc';
}
if (isset($subs[$this->view]['order'])) {
$order = $subs[$this->view]['order'];
}
$ordercols = '';
switch ($orderby) {
case 'name':
$order = 'title';
if ('desc' == $orderd) {
$order = 'reverse';
}
break;
case 'price':
$order = 'lowprice';
if ('desc' == $orderd) {
$order = 'highprice';
}
break;
case 'date':
$order = 'newest';
if ('desc' == $orderd) {
$order = 'oldest';
}
break;
case 'sold':
$ordercols = 's.sold ' . $orderd;
break;
case 'gross':
$ordercols = 's.grossed ' . $orderd;
break;
case 'inventory':
$ordercols = 's.stock ' . $orderd;
break;
case 'sku':
$ordercols = 'pt.sku ' . $orderd;
break;
}
if (in_array($this->view, array('onsale', 'featured', 'inventory'))) {
$joins[$ps] = "INNER JOIN {$ps} AS s ON p.ID=s.product";
}
$loading = array('where' => $where, 'joins' => $joins, 'limit' => "{$start},{$per_page}", 'load' => array('categories', 'coverimages'), 'published' => false, 'order' => $order, 'nostock' => true);
if (!empty($ordercols)) {
unset($loading['order']);
$loading['orderby'] = $ordercols;
}
if ($is_inventory) {
// Override for inventory products
$where[] = "(pt.context='product' OR pt.context='variation') AND pt.type != 'N/A'";
$loading = array('columns' => "pt.id AS stockid,IF(pt.context='variation',CONCAT(p.post_title,': ',pt.label),p.post_title) AS post_title,pt.sku AS sku,pt.stock AS stock", 'joins' => array_merge(array($pt => "LEFT JOIN {$pt} AS pt ON p.ID=pt.product"), $joins), 'where' => $where, 'groupby' => 'pt.id', 'orderby' => str_replace('s.', 'pt.', $ordercols), 'limit' => "{$start},{$per_page}", 'nostock' => true, 'published' => false);
}
// Override loading product meta and limiting by pagination in the workflow list
if ($workflow) {
unset($loading['limit']);
$loading['ids'] = true;
$loading['pagination'] = false;
$loading['load'] = array();
}
$this->products = new ProductCollection();
$this->products->load($loading);
// Overpagination protection, redirect to page 1 if the requested page doesn't exist
$num_pages = ceil($this->products->total / $per_page);
if ($paged > 1 && $paged > $num_pages) {
Shopp::redirect(add_query_arg('paged', null, $url));
}
// Return a list of product keys for workflow list requests
if ($workflow) {
return $this->products->worklist();
}
// Get sub-screen counts
$subcounts = Shopp::cache_get('shopp_product_subcounts', 'shopp_admin');
if ($subcounts) {
foreach ($subcounts as $name => $total) {
if (isset($subs[$name])) {
$subs[$name]['total'] = $total;
}
}
} else {
$subcounts = array();
foreach ($subs as $name => &$subquery) {
$subquery['total'] = 0;
$query = array('columns' => "count(*) AS total", 'table' => "{$pd} as p", 'joins' => array(), 'where' => array());
$query = array_merge($query, $subquery);
$query['where'][] = "p.post_type='shopp_product'";
if (in_array($name, array('onsale', 'bestselling', 'featured', 'inventory'))) {
$query['joins'][$ps] = "INNER JOIN {$ps} AS s ON p.ID=s.product";
}
$query = sDB::select($query);
$subquery['total'] = sDB::query($query, 'auto', 'col', 'total');
$subcounts[$name] = $subquery['total'];
}
Shopp::cache_set('shopp_product_subcounts', $subcounts, 'shopp_admin');
}
$this->subs = $subs;
}
示例3: load
/**
* Loads the requested image for display
*
* @author Jonathan Davis
* @since 1.1
* @return boolean Status of the image load
**/
public function load()
{
$cache = 'image_' . $this->request . ($this->valid ? '_' . $this->valid : '');
$cached = Shopp::cache_get($cache, 'shopp_image');
if ($cached) {
return $this->Image = $cached;
}
$this->Image = new ImageAsset($this->request);
if (max($this->width, $this->height) > 0) {
$this->loadsized();
}
Shopp::cache_set($cache, $this->Image, 'shopp_image');
do_action('shopp_imageserver_load', $this->Image);
if (!empty($this->Image->id) || !empty($this->Image->data)) {
return true;
} else {
return false;
}
}