Skip to content

Commit 6fdc883

Browse files
committed
2.4.1
1 parent b6430c4 commit 6fdc883

File tree

5 files changed

+55
-29
lines changed

5 files changed

+55
-29
lines changed

src/inc/functions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,13 @@ function slw_clear_debug_log(){
241241
wp_die();
242242
}
243243
}
244+
244245
add_action( 'pmxi_saved_post', function( $id )
245246
{
247+
$import_id = ( isset( $_GET['id'] ) ? $_GET['id'] : ( isset( $_GET['import_id'] ) ? $_GET['import_id'] : 'new' ) );
246248
// get locations total stock
247249
$locations_total_stock = \SLW\SRC\Helpers\SlwProductHelper::get_product_locations_stock_total( $id );
248-
250+
249251
// update stock
250252
slw_update_product_stock_status( $id, $locations_total_stock );
251253

src/readme.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ On settings page you can define a number. If location stock value will be less t
152152

153153

154154
== Changelog ==
155+
156+
= 2.4.1 =
157+
- Fix: Products get put from out of stock to backorder automatically. [Thanks to Ole Straume Andersen][23/11/2022]
158+
- Fix: Total Stock was wrong when stock locations has negative value. [Thanks to michaelw90][27/12/2022]
159+
155160
= 2.4.0 =
156161
- Improvement: Default location will be set for the recently modified/new products. [Thanks to PHILIPP GOLOB][19/11/2022]
157162

src/src/classes/class-slw-stock-locations-tab.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function tab_content_stock_locations_wc_product( $array )
136136
echo '<div id="' . $this->tab_stock_locations . '_total"><u>' . __('Total Stock:', 'stock-locations-for-woocommerce') . ' <b>' . ($product->get_stock_quantity() + 0) . '</b></u></div>';
137137
echo '<hr>';
138138
}
139-
139+
//pree($product->get_stock_quantity());pree($postmeta);
140140
// Convert $postmeta array values from string to int
141141

142142
// Check if the total stock matches the sum of the locations stock, if not show warning message
@@ -316,7 +316,7 @@ public static function save_tab_data_stock_locations_wc_product_save( $post_id,
316316

317317
}
318318
}
319-
319+
320320
// Product location terms
321321
$product_stock_location_terms = wp_get_post_terms($post_id, SlwLocationTaxonomy::get_tax_Names('singular'));
322322

@@ -326,7 +326,7 @@ public static function save_tab_data_stock_locations_wc_product_save( $post_id,
326326
} else{
327327
$terms_total = count($product_stock_location_terms);
328328
}
329-
329+
330330
// On product update
331331
if( $update ){
332332

@@ -348,18 +348,21 @@ public static function save_tab_data_stock_locations_wc_product_save( $post_id,
348348

349349
$stock_value = self::update_product_stock($item_id, $product_stock_location_terms, $terms_total, $force);
350350

351-
352-
$master_stock_value += $stock_value;
351+
if($stock_value>0){
352+
$master_stock_value += $stock_value;
353+
}
353354

354355
}
355356

356357

357358

358359
}else{
359-
$master_stock_value = $stock_value;
360+
if($stock_value>0){
361+
$master_stock_value = $stock_value;
362+
}
360363
}
361364

362-
365+
//pree($master_stock_value);exit;
363366
slw_update_product_stock_status($post_id, $master_stock_value);
364367

365368

@@ -519,7 +522,14 @@ public static function update_product_stock( $id, $product_stock_location_terms,
519522

520523
if(!$slw_location_status){ continue; }
521524
// Save input amounts to array
522-
$input_amounts[] = sanitize_slw_data($_POST[$stock_input_id]);
525+
526+
$input_amount = sanitize_slw_data($_POST[$stock_input_id]);
527+
528+
if($input_amount>0){
529+
$input_amounts[] = $input_amount;
530+
}else{
531+
continue;
532+
}
523533

524534

525535
// Check if input is empty

src/src/classes/frontend/class-slw-frontend-cart.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,18 @@ public function add_cart_item_stock_locations( $cart_item, $cart_item_key )
128128
$lock_default_location = isset( $this->plugin_settings['lock_default_location_in_frontend'] ) && $this->plugin_settings['lock_default_location_in_frontend'] == 'on' ? true : false;
129129
$stock_location_selected = ((isset($woocommerce->session) && $woocommerce->session->has_session())?$woocommerce->session->get('stock_location_selected'):0);
130130

131+
131132
$different_location_per_cart_item = (isset($this->plugin_settings['different_location_per_cart_item'])?$this->plugin_settings['different_location_per_cart_item']:'');
132133
$different_location_per_cart_item_no = (isset($this->plugin_settings['different_location_per_cart_item_no'])?$this->plugin_settings['different_location_per_cart_item_no']:'');
133134

134135

135136

136137
if(array_key_exists('stock_location', $cart_item) && !is_array($cart_item['stock_location']) && $cart_item['stock_location']>0){
138+
$stock_location_selected = ($stock_location_selected?$stock_location_selected:$cart_item['stock_location']);
137139
$cart_item['stock_location'] = (is_array($cart_item['stock_location'])?$cart_item['stock_location']:array($product_id=>$cart_item['stock_location']));
138140
}
139-
141+
142+
140143
if( !empty($stock_locations) ) {
141144

142145
if( isset($this->plugin_settings['show_in_cart']) && $this->plugin_settings['show_in_cart'] == 'yes' ) {
@@ -146,7 +149,7 @@ public function add_cart_item_stock_locations( $cart_item, $cart_item_key )
146149
$stock_locations_arr[] = $location['term_id'];
147150
}
148151

149-
if(!in_array($stock_location_selected, $stock_locations_arr) && $different_location_per_cart_item=='no' && $different_location_per_cart_item_no == 'continue'){
152+
if($stock_location_selected && !in_array($stock_location_selected, $stock_locations_arr) && $different_location_per_cart_item=='no' && $different_location_per_cart_item_no == 'continue'){
150153
$product_name = ($cart_item['data']->get_data()['name']);
151154

152155
$slw_notice_msg = apply_filters('slw_notice_msg', sprintf( __('This product item is not available on the selected store location. %s', 'stock-locations-for-woocommerce'), '<a class="button alt slw-dismiss-notice">'.__('Dismiss', 'stock-locations-for-woocommerce').'</a>'), $product_id, $product_name, $stock_location_selected, $stock_locations_arr);
@@ -156,27 +159,33 @@ public function add_cart_item_stock_locations( $cart_item, $cart_item_key )
156159
}
157160

158161
if(
159-
isset($this->plugin_settings['different_location_per_cart_item'])
160-
&&
161162
(
162-
$this->plugin_settings['different_location_per_cart_item'] == 'yes'
163-
164-
||
165-
166-
(
167-
$this->plugin_settings['different_location_per_cart_item'] == 'no'
168-
&&
169-
(
170-
in_array($stock_location_selected, $stock_locations_arr)
171-
//||
172-
//$different_location_per_cart_item_no == 'continue'
173-
)
174-
175-
)
163+
isset($this->plugin_settings['different_location_per_cart_item'])
164+
&&
165+
(
166+
$this->plugin_settings['different_location_per_cart_item'] == 'yes'
167+
168+
||
169+
170+
(
171+
$this->plugin_settings['different_location_per_cart_item'] == 'no'
172+
&&
173+
(
174+
in_array($stock_location_selected, $stock_locations_arr)
175+
//||
176+
//$different_location_per_cart_item_no == 'continue'
177+
)
178+
179+
)
180+
)
176181
)
182+
183+
||
184+
185+
!$stock_location_selected
177186
) {
178187

179-
echo '<label class="slw_cart_item_stock_location_label">'.__('Nearest Location', 'stock-locations-for-woocommerce').':</label>';
188+
echo '<label class="slw_cart_item_stock_location_label">'.__('Location', 'stock-locations-for-woocommerce').':</label>';
180189

181190
// lock to default location if enabled
182191
if( $lock_default_location && $default_location != 0 ) {

src/stock-locations-for-woocommerce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
class SlwMain{
9595
// versions
96-
public $version = '2.4.0';
96+
public $version = '2.4.1';
9797
public $import_export_addon_version = '1.1.1';
9898

9999
// others

0 commit comments

Comments
 (0)