Example #1
0
 /**
  * @depends testRemoveCategory
  */
 public function testAddAccessory(ProductModel $product)
 {
     $accessories = AccessoryQuery::create()->filterByProductId($product->getId())->count();
     $this->assertEquals(0, $accessories);
     $accessoryId = ProductQuery::create()->select('id')->filterById($product->getId(), Criteria::NOT_IN)->addAscendingOrderByColumn('RAND()')->findOne();
     $event = new ProductAddAccessoryEvent($product, $accessoryId);
     $event->setDispatcher($this->getDispatcher());
     $action = new Product();
     $action->addAccessory($event);
     $newAccessories = AccessoryQuery::create()->filterByProductId($product->getId())->count();
     $this->assertEquals(1, $newAccessories);
     return $product;
 }
Example #2
0
 public function addAccessory(ProductAddAccessoryEvent $event)
 {
     if (AccessoryQuery::create()->filterByAccessory($event->getAccessoryId())->filterByProductId($event->getProduct()->getId())->count() <= 0) {
         $accessory = new Accessory();
         $accessory->setDispatcher($event->getDispatcher())->setProductId($event->getProduct()->getId())->setAccessory($event->getAccessoryId())->save();
     }
 }