Example #1
0
 /**
  * Формирует ассортимент, используя массив $productId => null,
  * и удаляет из ассортимента те продукты, которые в данном массиве
  * не определены.
  * 
  * @param array $productIds
  * @return boolean 
  */
 public function map(array $productIds = null)
 {
     $existedRecords = $this->ls();
     $products = Product::ls();
     foreach ($products as $product) {
         if (isset($productIds[$product->id])) {
             $isExisted = false;
             foreach ($existedRecords as $record) {
                 if ($record->productId == $product->id) {
                     $isExisted = true;
                     continue;
                 }
             }
             if ($isExisted && !$productIds[$product->id]) {
                 $this->remove($product);
             } else {
                 if (!$isExisted && $productIds[$product->id]) {
                     $this->add($product);
                 }
             }
         } else {
             $this->remove($product);
         }
     }
     return true;
 }
Example #2
0
 public function Index()
 {
     return array('products' => Product::ls());
 }
Example #3
0
 public function Index()
 {
     return array('stores' => Store::ls(), 'persons' => Person::ls(), 'products' => Product::ls());
 }