/** * Calculate order shipping price * * @param type $postcode = Postcode to calculate price * @param type $default = Default return value if postcode dont exist or not set * @param type $default = * @return type */ public function shipping_price($postcode = null, $default = null, $force_current_user = false) { // Default postcode to users postcode if (is_null($postcode)) { if ($force_current_user) { if (\Model_Base::check_logged()) { $user = \Sentry::user(); $postcode = $user->get('metadata.postcode'); } } else { $postcode = $this->user->get('metadata.postcode'); } } // Load shipping configuration \Config::load('product::shipping', 'shipping', true); $prices = \Arr::sort(\Config::get('shipping.price', array()), 'from'); if (!is_numeric($default)) { $default = \Config::get('shipping.default', 0); } $target_price = $default; // If we dont have postcode we return zero shipping price if (!$postcode || !is_numeric($postcode)) { return $target_price; } // Find coresponding price for this postcode foreach ($prices as $price) { if ($price['from'] <= $postcode && $price['to'] >= $postcode) { $target_price = $price['price']; break; } } // return $target_price; // no shipping price for enviroform site return $default; }
public static function filter_by_group() { $out['assigned'] = array(); $out['not_assigned'] = array(); $products_assigned = array(); $products_not_assigned = array(); $in_groups = array(); $not_in_groups = array(); if (parent::check_logged()) { $groups = Model_Group_Options::find(array(), 'product_group_id'); $user = \Sentry::user(); $user_group = $user->groups(); $user_group = $user_group[0]; if (isset($user_group['id'])) { $in_groups = Model_Group_Options::find(array('where' => array('user_group_id' => $user_group['id'], 'able_to_buy' => 1)), 'product_group_id'); $not_in_groups = Model_Group_Options::find(array('where' => array(array('user_group_id', '!=', $user_group['id']))), 'product_group_id'); if (!is_array($in_groups)) { $in_groups = array(); } if (!is_array($not_in_groups)) { $not_in_groups = array(); } $not_in_groups = array_diff_key($not_in_groups, $in_groups); } } else { $not_in_groups = Model_Group_Options::find(array(), 'product_group_id'); } if (!empty($in_groups)) { $groups = '(' . implode(',', array_keys($in_groups)) . ')'; $products_assigned = Model_Product_To_Groups::find(function ($query) use($groups) { $query->where('group_id', 'IN', \DB::expr($groups)); return $query; }, 'product_id'); } if (!empty($not_in_groups)) { $groups = '(' . implode(',', array_keys($not_in_groups)) . ')'; $products_not_assigned = Model_Product_To_Groups::find(function ($query) use($groups) { $query->where('group_id', 'IN', \DB::expr($groups)); return $query; }, 'product_id'); } $out['assigned'] = $products_assigned; $out['not_assigned'] = $products_not_assigned; return $out; }