Example #1
0
 /**
  * Tri un tableau
  */
 public static function sort(&$obj, $key, $order = SORT_DESC)
 {
     if ($obj) {
         self::toArray($obj);
         Arr::sort($obj, $key, $order);
         Arr::toObject($obj);
     }
 }
Example #2
0
 /**
  * Sort the array using the given Closure.
  *
  * @param  array     $array
  * @param  \Closure  $callback
  * @return array
  */
 function array_sort($array, Closure $callback)
 {
     return Arr::sort($array, $callback);
 }
Example #3
0
 /**
  * Tests Arr::sort()
  *
  * @test
  * @dataProvider sort_provider
  * @expectedException InvalidArgumentException
  */
 public function test_sort_invalid_direction($data, $expected)
 {
     $this->assertEquals(Arr::sort($data, 'info.pet.type', 'downer'), $expected);
 }
Example #4
0
 public function test_sort_empty()
 {
     $expected = array();
     $output = Arr::sort(array(), 'test', 'test');
     $this->assertEquals($expected, $output);
 }
Example #5
0
 /**
  * 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;
 }