Пример #1
0
 public function load(array $options = array())
 {
     $this->loading = $options = array_merge($this->_options, $options);
     if (isset($this->loading['show'])) {
         $this->loading['limit'] = $this->loading['show'];
         unset($this->loading['show']);
     }
     if (isset($options['pagination'])) {
         $this->loading['pagination'] = $options['pagination'];
     }
     if (isset($options['exclude'])) {
         $exclude = $options['exclude'];
         if (is_numeric(str_replace(',', '', $exclude))) {
             global $wpdb;
             $this->loading['joins'][] = "INNER JOIN {$wpdb->term_relationships} as tr ON p.ID = tr.object_id";
             $this->loading['joins'][] = "INNER JOIN {$wpdb->term_taxonomy} as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
             $this->loading['where'][] = "tr.term_taxonomy_id NOT IN ({$exclude})";
             $this->loading['where'][] = "tt.taxonomy = 'shopp_category'";
         }
     }
     $this->smart($this->loading);
     parent::load($this->loading);
 }
Пример #2
0
    /**
     * Renders the bestselling products dashboard widget
     *
     * @author Jonathan Davis
     * @since 1.0
     *
     * @return void
     **/
    public static function inventory_widget($args = false)
    {
        $warnings = array('none' => __('OK', 'Shopp'), 'warning' => __('warning', 'Shopp'), 'critical' => __('critical', 'Shopp'), 'backorder' => __('backorder', 'Shopp'));
        $defaults = array('before_widget' => '', 'before_title' => '', 'widget_name' => '', 'after_title' => '', 'after_widget' => '');
        $args = array_merge($defaults, (array) $args);
        extract($args, EXTR_SKIP);
        $pt = ShoppDatabaseObject::tablename(ShoppPrice::$table);
        $setting = shopp_setting('lowstock_level');
        $where = array();
        $where[] = "pt.stock < pt.stocked AND pt.stock/pt.stocked < {$setting}";
        $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,pt.stocked", 'joins' => array($pt => "LEFT JOIN {$pt} AS pt ON p.ID=pt.product"), 'where' => $where, 'groupby' => 'pt.id', 'orderby' => '(pt.stock/pt.stocked) ASC', 'published' => false, 'pagination' => false, 'limit' => 25);
        $Collection = new ProductCollection();
        $Collection->load($loading);
        $productscreen = add_query_arg(array('page' => ShoppAdmin::pagename('products')), admin_url('admin.php'));
        echo $before_widget;
        echo $before_title;
        echo $widget_name;
        echo $after_title;
        ?>
		<table><tbody>
		<?php 
        foreach ($Collection->products as $product) {
            $product->lowstock($product->stock, $product->stocked);
            ?>
		<tr>
			<td class="amount"><?php 
            echo abs($product->stock);
            ?>
</td>
			<td><span class="stock lowstock <?php 
            echo $product->lowstock;
            ?>
"><?php 
            echo $warnings[$product->lowstock];
            ?>
</span></td>
			<td><a href="<?php 
            echo esc_url(add_query_arg('id', $product->id, $productscreen));
            ?>
"><?php 
            echo $product->name;
            ?>
</a></td>
			<td><a href="<?php 
            echo esc_url(add_query_arg('view', 'inventory', $productscreen));
            ?>
"><?php 
            echo $product->sku;
            ?>
</a></td>
		</tr>
		<?php 
        }
        ?>
		</tbody></table>

		<?php 
        echo $after_widget;
    }
Пример #3
0
 public function upgrade_130()
 {
     global $wpdb;
     $db_version = ShoppSettings::dbversion();
     if ($db_version < 1201) {
         // 1.3 schema changes
         $this->upschema();
         // All existing sessions must be cleared and restarted, 1.3 & 1.3.6 sessions are not compatible with any prior version of Shopp
         ShoppShopping()->reset();
         $sessions_table = ShoppDatabaseObject::tablename('shopping');
         sDB::query("DELETE FROM {$sessions_table}");
         // Remove all the temporary PHP native session data from the options table
         sDB::query("DELETE FROM from {$wpdb->options} WHERE option_name LIKE '__php_session_*'");
     }
     if ($db_version < 1200) {
         $meta_table = ShoppDatabaseObject::tablename('meta');
         sDB::query("UPDATE {$meta_table} SET value='on' WHERE name='theme_templates' AND (value != '' AND value != 'off')");
         sDB::query("DELETE FROM {$meta_table} WHERE type='image' AND value LIKE '%O:10:\"ShoppError\"%'");
         // clean up garbage from legacy bug
         sDB::query("DELETE FROM {$meta_table} WHERE CONCAT('', name *1) = name AND context = 'category' AND type = 'meta'");
         // clean up bad category meta
         // Update purchase gateway values to match new prefixed class names
         $gateways = array('PayPalStandard' => 'ShoppPayPalStandard', '_2Checkout' => 'Shopp2Checkout', 'OfflinePayment' => 'ShoppOfflinePayment', 'TestMode' => 'ShoppTestMode', 'FreeOrder' => 'ShoppFreeOrder');
         foreach ($gateways as $name => $classname) {
             sDB::query("UPDATE {$purchase_table} SET gateway='{$classname}' WHERE gateway='{$name}'");
         }
         $activegateways = explode(',', shopp_setting('active_gateways'));
         foreach ($activegateways as &$setting) {
             if (false === strpos($setting, 'Shopp')) {
                 $setting = str_replace(array_keys($gateways), $gateways, $setting);
             }
         }
         shopp_set_setting('active_gateways', join(',', $activegateways));
     }
     if ($db_version < 1200 && shopp_setting_enabled('tax_inclusive')) {
         $price_table = ShoppDatabaseObject::tablename('price');
         $taxrates = shopp_setting('taxrates');
         $baseop = shopp_setting('base_operations');
         $taxtaxes = array();
         // Capture taxonomy condition tax rates
         $basetaxes = array();
         // Capture base of operations rate(s)
         foreach ($taxrates as $rate) {
             if (!($baseop['country'] == $rate['country'] || ShoppTax::ALL == $rate['country'])) {
                 continue;
             }
             if (!empty($rate['zone']) && $baseop['zone'] != $rate['zone']) {
                 continue;
             }
             if (!empty($rate['rules']) && $rate['logic'] == 'any') {
                 // Capture taxonomy conditional rates
                 foreach ($rate['rules'] as $raterule) {
                     if ('product-category' == $raterule['p']) {
                         $taxname = ProductCategory::$taxon . '::' . $raterule['v'];
                     } elseif ('product-tags' == $raterule['p']) {
                         $taxname = ProductTag::$taxon . '::' . $raterule['v'];
                     }
                     $taxtaxes[$taxname] = Shopp::floatval($rate['rate']) / 100;
                 }
             } else {
                 $basetaxes[] = Shopp::floatval($rate['rate']) / 100;
             }
         }
         // Find products by in each taxonomy termno
         $done = array();
         // Capture each set into the "done" list
         foreach ($taxtaxes as $taxterm => $taxrate) {
             list($taxonomy, $name) = explode('::', $taxterm);
             $Collection = new ProductCollection();
             $Collection->load(array('ids' => true, 'taxquery' => array(array('taxonomy' => $taxonomy, 'field' => 'name', 'terms' => $name))));
             $query = "UPDATE {$price_table} SET price=price+(price*{$taxrate}) WHERE tax='on' AND product IN (" . join(',', $Collection->products) . ")";
             sDB::query($query);
             $done = array_merge($done, $Collection->products);
         }
         // Update the rest of the prices (skipping those we've already done) with the tax rate that matches the base of operations
         $taxrate = array_sum($basetaxes);
         // Merge all the base taxes into a single rate
         $done = empty($done) ? '' : " AND product NOT IN (" . join(',', $done) . ")";
         $query = "UPDATE {$price_table} SET price=price+(price*{$taxrate}) WHERE tax='on'{$done}";
         sDB::query($query);
     }
 }