Example #1
0
 public function testNodeIsSoftDeleted()
 {
     $root = Category::root();
     $samsung = $this->findCategory('samsung');
     $samsung->delete();
     $this->assertTreeNotBroken();
     $this->assertNull($this->findCategory('galaxy'));
     sleep(1);
     $node = $this->findCategory('mobile');
     $node->delete();
     $nodes = Category::whereIn('id', array(5, 6, 7, 8, 9))->count();
     $this->assertEquals(0, $nodes);
     $originalRgt = $root->getRgt();
     $root->refreshNode();
     $this->assertEquals($originalRgt, $root->getRgt());
     $node = $this->findCategory('mobile', true);
     $node->restore();
     $this->assertNull($this->findCategory('samsung'));
 }
Example #2
0
 public function testDescendantsEagerlyLoaded()
 {
     $nodes = Category::whereIn('id', [2, 5])->get();
     $nodes->load('descendants');
     $this->assertEquals(2, $nodes->count());
     $this->assertTrue($nodes->first()->relationLoaded('descendants'));
 }
 /**
  * Get sub categories for rendering sub category.
  *
  * @return void
  */
 public function getCategories()
 {
     global $data;
     global $settings;
     if (in_array('customer', $settings['list_display_ways'])) {
         unset($settings['list_display_ways'][array_search('customer', $settings['list_display_ways'])]);
         $settings['list_display_ways'][] = $settings['customer_category'];
     }
     $categories = Category::whereIn('code', $settings['list_display_ways'])->get()->toArray();
     $array = array();
     foreach ($categories as $key => $row) {
         $row['settings'] = json_decode($row['settings'], true);
         $array[$row['code']] = $row;
     }
     $data['categories'] = $array;
 }