Skip to content

Commit

Permalink
Allow order country filters to apply to models that belong to the sho…
Browse files Browse the repository at this point in the history
…p order model
  • Loading branch information
damanic committed Sep 6, 2021
1 parent 54b127f commit 35010a6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
17 changes: 13 additions & 4 deletions classes/shop_orderbillingcountryfilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ class Shop_OrderBillingCountryFilter extends Db_DataFilter

public function applyToModel($model, $keys, $context = null)
{
if ($context != 'product_report')
$model->where('billing_country_id in (?)', array($keys));
else
$model->where('shop_orders.billing_country_id in (?)', array($keys));
if(is_a($model,'Shop_Order')){
$model->where('shop_orders.billing_country_id IN (?)', array($keys));
} else if ($model->belongs_to) {
foreach($model->belongs_to as $field => $belongs_to_info){
$class_name = isset($belongs_to_info['class_name']) ? $belongs_to_info['class_name'] : null;
if($class_name == 'Shop_Order'){
$foreign_key = $belongs_to_info['foreign_key'];
if($foreign_key){
$model->where($field.'_calculated_join.billing_country_id IN (?)', array($keys));
}
}
}
}
}

public function asString($keys, $context = null)
Expand Down
17 changes: 13 additions & 4 deletions classes/shop_ordershippingcountryfilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ class Shop_OrderShippingCountryFilter extends Db_DataFilter

public function applyToModel($model, $keys, $context = null)
{
if ($context != 'product_report')
$model->where('shipping_country_id in (?)', array($keys));
else
$model->where('shop_orders.shipping_country_id in (?)', array($keys));
if(is_a($model,'Shop_Order')){
$model->where('shop_orders.shipping_country_id IN (?)', array($keys));
} else if ($model->belongs_to) {
foreach($model->belongs_to as $field => $belongs_to_info){
$class_name = isset($belongs_to_info['class_name']) ? $belongs_to_info['class_name'] : null;
if($class_name == 'Shop_Order'){
$foreign_key = $belongs_to_info['foreign_key'];
if($foreign_key){
$model->where($field.'_calculated_join.shipping_country_id IN (?)', array($keys));
}
}
}
}
}

public function asString($keys, $context = null)
Expand Down
17 changes: 13 additions & 4 deletions classes/shop_ordershippingzonefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ public function applyToModel($model, $keys, $context = null)
if(!$country_ids){
$country_ids = array('0'); //no countries, no results
}
if ( $context != 'product_report' ) {
$model->where( 'shipping_country_id in (?)', array( $country_ids ) );
} else {
$model->where( 'shop_orders.shipping_country_id in (?)', array( $country_ids ) );

if(is_a($model,'Shop_Order')){
$model->where('shop_orders.shipping_country_id IN (?)', array($country_ids));
} else if ($model->belongs_to) {
foreach($model->belongs_to as $field => $belongs_to_info){
$class_name = isset($belongs_to_info['class_name']) ? $belongs_to_info['class_name'] : null;
if($class_name == 'Shop_Order'){
$foreign_key = $belongs_to_info['foreign_key'];
if($foreign_key){
$model->where($field.'_calculated_join.shipping_country_id IN (?)', array($country_ids));
}
}
}
}

}
Expand Down

0 comments on commit 35010a6

Please sign in to comment.