/[drupal]/contributions/modules/uc_multi_stock/uc_multi_stock.module
ViewVC logotype

Diff of /contributions/modules/uc_multi_stock/uc_multi_stock.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.3, Sun Sep 7 01:15:56 2008 UTC revision 1.1.2.3.2.1, Sun Feb 1 01:23:30 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id:
3    
4  /**  /**
5   * @file   * prevent purchasing pruducts below stock levels.
  * prevent purchasing of pruducts below stock levels.  
6   *   *
7   * this module includes some code from the Inventory API & Simple Stock Levels   * this module includes some code from the Inventory API & Simple Stock Levels
8   * (http://www.ubercart.org/contrib/132), by CpILL (http://www.ubercart.org/user/29).   * (http://www.ubercart.org/contrib/132), by CpILL (http://www.ubercart.org/user/29).
# Line 15  Line 14 
14   ******************************************************************************/   ******************************************************************************/
15    
16  /**  /**
17     * Implementation of hook_theme().
18     */
19    function uc_multi_stock_theme() {
20      return array(
21        'uc_multi_stock_out_of_stock_error' => array(
22          'arguments' => array('stock' => NULL, 'threshold' => NULL, 'product' => NULL, 'attributes' => NULL),
23        ),
24        'uc_multi_stock_too_many_in_order_error' => array(
25          'arguments' => array('qty' => NULL, 'product' => NULL, 'attributes' => NULL),
26        ),
27      );
28    }
29    
30    /**
31   * Implementation of hook_menu().   * Implementation of hook_menu().
32   */   */
33  function uc_multi_stock_menu($may_cache) {  function uc_multi_stock_menu() {
34    if ($may_cache) {    $items['admin/store/settings/multi_stock'] = array(
35      $items[] = array(      'title' => 'Multi Stock Settings',
36        'path' => 'admin/store/settings/multi_stock',      'access callback' => 'user_access',
37        'title' => t('Multi Stock Settings'),      'access arguments' => array('administer store'),
38        'access' => user_access('administer store'),      'description' => 'Configure multi stock settings.',
39        'description' => t('Configure multi stock settings.'),      'page callback' => 'drupal_get_form',
40        'callback' => 'drupal_get_form',      'page arguments' => array('uc_multi_stock_settings'),
41        'callback arguments' => array('uc_multi_stock_settings'),      'type' => MENU_NORMAL_ITEM,
42        'type' => MENU_NORMAL_ITEM,    );
     );  
   }  
43    return $items;    return $items;
44  }  }
45    
# Line 37  function uc_multi_stock_menu($may_cache) Line 48  function uc_multi_stock_menu($may_cache)
48   *   *
49   * Add validation for cart view form.   * Add validation for cart view form.
50   */   */
51  function uc_multi_stock_form_alter($form_id, &$form) {  function uc_multi_stock_form_alter(&$form, $form_state, $form_id) {
52    // create validations for all the product forms    // create validations for all the product forms
53    switch ($form_id) {    switch ($form_id) {
54      case 'uc_cart_view_form':      case 'uc_cart_view_form':
55        //$form['#validate'] = array('uc_multi_stock_uc_cart_view_validate' => array()) + $form['#validate'];        //$form['#validate'] = array('uc_multi_stock_uc_cart_view_validate' => array()) + $form['#validate'];
56        $form['#validate'] = array('uc_multi_stock_uc_cart_view_validate' => array());        $form['#validate'][] = 'uc_multi_stock_uc_cart_view_validate';
57        break;        break;
58    }    }
59  }  }
# Line 66  function uc_multi_stock_cart_item($op, & Line 77  function uc_multi_stock_cart_item($op, &
77  }  }
78    
79  /**  /**
80   * Implementation of hook_add_to_cart().   * Implementation of hook_add_to_cart()
81   *   *
82   * prevent addition of out of stock products   * prevent addition of out of stock products
83   */   */
# Line 104  function uc_multi_stock_add_to_cart($nid Line 115  function uc_multi_stock_add_to_cart($nid
115   *   *
116   * Final check with the Inventory Manager before allowing purchase   * Final check with the Inventory Manager before allowing purchase
117   */   */
118  function uc_multi_stock_order($op, &$order, $arg = NULL) {  function uc_multi_stock_order($op, &$order, $arg = null) {
119    switch ($op) {    switch ($op) {
120      case 'submit':      case 'submit':
121        $errors = array();        $errors = array();
# Line 153  function uc_multi_stock_settings() { Line 164  function uc_multi_stock_settings() {
164  /**  /**
165   * validate the view cart form   * validate the view cart form
166   */   */
167  function uc_multi_stock_uc_cart_view_validate($form_id, $form_values) {  function uc_multi_stock_uc_cart_view_validate($form, &$form_state) {
   
168    // for every item in the cart    // for every item in the cart
169    foreach ($form_values['items'] as $item) {    foreach ($form_state['values']['items'] as $item) {
170      $nid = $item['nid'];      $nid = $item['nid'];
171      $data = unserialize($item['data']);      $data = unserialize($item['data']);
172    
# Line 166  function uc_multi_stock_uc_cart_view_val Line 176  function uc_multi_stock_uc_cart_view_val
176      $sku = uc_multi_get_sku($nid, $data['attributes']);      $sku = uc_multi_get_sku($nid, $data['attributes']);
177    
178      // dont test the removal of out of stock products      // dont test the removal of out of stock products
179      if (!$item['remove'] && $item['qty']>0) {      if (empty($item['remove']) && $item['qty']>0) {
180        $tmp_error = uc_multi_stock_can_buy($product, $sku, $item['qty'], $data['attributes']);        $tmp_error = uc_multi_stock_can_buy($product, $sku, $item['qty'], $data['attributes']);
181        if ($tmp_error) {        if ($tmp_error) {
182          $error .= $tmp_error .'<br /><br />';          $error .= $tmp_error .'<br /><br />';
# Line 183  function uc_multi_stock_uc_cart_view_val Line 193  function uc_multi_stock_uc_cart_view_val
193   * Test if we can buy this product.   * Test if we can buy this product.
194   */   */
195  function uc_multi_stock_can_buy($product, $sku, $qty, $attributes) {  function uc_multi_stock_can_buy($product, $sku, $qty, $attributes) {
196    
197    // test for missing sku - can happen when the deafult option is selected    // test for missing sku - can happen when the deafult option is selected
198    if (!$sku) {    if (!$sku) {
199      $sku = $product->model;      $sku = $product->model;
# Line 196  function uc_multi_stock_can_buy($product Line 207  function uc_multi_stock_can_buy($product
207      if (variable_get('uc_multi_stock_use_thershold', FALSE)) {      if (variable_get('uc_multi_stock_use_thershold', FALSE)) {
208        $stock_qty = $stock->threshold;        $stock_qty = $stock->threshold;
209      }      }
210    
211      // check for out of stock      // check for out of stock
212      $error = uc_multi_stock_not_in_stock($stock->stock, $stock_qty, $product, $attributes);      $error = uc_multi_stock_not_in_stock($stock->stock, $stock_qty, $product, $attributes);
213      if ($error) {      if ($error) {
# Line 233  function uc_multi_stock_not_enough_in_st Line 245  function uc_multi_stock_not_enough_in_st
245  /**  /**
246   * themeable error messages   * themeable error messages
247   */   */
248  function theme_uc_multi_stock_out_of_stock_error($product = NULL, $attributes) {  function theme_uc_multi_stock_out_of_stock_error($product = null, $attributes) {
249    if (is_array($attributes) and count($attributes) > 0) {    if (is_array($attributes) and count($attributes) > 0) {
250      return (t("We're sorry. The @product in your selected size/color combination is out of stock.  Please consider another size/color in this style.", array('@product' => $product->title)));      return (t("We're sorry. The @product in your selected size/color combination is out of stock.  Please consider another size/color in this style.", array('@product' => $product->title)));
251    }    }
# Line 242  function theme_uc_multi_stock_out_of_sto Line 254  function theme_uc_multi_stock_out_of_sto
254    }    }
255  }  }
256    
257  function theme_uc_multi_stock_too_many_in_order_error($qty = 0, $product = NULL , $attributes) {  function theme_uc_multi_stock_too_many_in_order_error($qty = 0, $product = null , $attributes) {
258    if (is_array($attributes) and count($attributes) > 0) {    if (is_array($attributes) and count($attributes) > 0) {
259      return (t("We're sorry.  We have only @qty unit(s) of the @product in your selected size/color combination left in stock.  Please try again with fewer units or consider another size/color in this style.", array('@qty' => $qty, '@product' => $product->title)));      return (t("We're sorry.  We have only @qty unit(s) of the @product in your selected size/color combination left in stock.  Please try again with fewer units or consider another size/color in this style.", array('@qty' => $qty, '@product' => $product->title)));
260    }    }
# Line 291  function uc_multi_get_subproducts($nid) Line 303  function uc_multi_get_subproducts($nid)
303    $out = array();    $out = array();
304    
305    if (!empty($nid) and module_exists('uc_attribute')) {    if (!empty($nid) and module_exists('uc_attribute')) {
306      $sql = 'SELECT * FROM {uc_product_adjustments} WHERE nid = '. $nid;      $sql = 'SELECT * FROM {uc_product_adjustments} WHERE nid = '.$nid;
307      $q = db_query($sql);          $q = db_query($sql);
308      $i = 0;          $i = 0;
309      while ($product = db_fetch_array($q)) {          while ($product = db_fetch_array($q)) {
310        $out[$i]['attributes'] = unserialize($product['combination']);                  $out[$i]['attributes'] = unserialize($product['combination']);
311        $out[$i]['model'] = $product['model'];                  $out[$i]['model'] = $product['model'];
312        $i++;                  $i++;
313      }          }
314      return $out;          return $out;
315    }    }
316    else {    else {
317      return array();          return array();
318    }    }
319  }  }
320    

Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.3.2.1

  ViewVC Help
Powered by ViewVC 1.1.2