Example #1
0
 /**
  * @param int $id
  * @param Product $record
  */
 public function handleRecord($id, $record)
 {
     $category_id = $this->grid->getRequest()->getInt('category_id');
     if (!$category_id) {
         throw new Am_Exception_InternalError("category_id empty");
     }
     $categories = $record->getCategories();
     if ($this->remove) {
         if (!in_array($category_id, $categories)) {
             return;
         }
         foreach ($categories as $k => $id) {
             if ($id == $category_id) {
                 unset($categories[$k]);
             }
         }
     } else {
         if (in_array($category_id, $categories)) {
             return;
         }
         $categories[] = $category_id;
     }
     $record->setCategories($categories);
 }
Example #2
0
 function testFindingByCategoryShouldFindOnlyActive()
 {
     $product_mapper = new DataMapper($this->db);
     $product = new Product(array('sku' => 'foo2'));
     $product->setCategories(array(1));
     $product_mapper->save($product);
     $product_mapper->deactivate($product->id());
     $products = $product_mapper->find(['active' => 1, 'category' => 1]);
     $this->assertEquals(0, count($products));
 }