예제 #1
0
 public function buildModelCriteria()
 {
     $search = AccessoryQuery::create();
     $product = $this->getProduct();
     $search->filterByProductId($product, Criteria::IN);
     $order = $this->getOrder();
     $orderByAccessory = array_search('accessory', $order);
     $orderByAccessoryReverse = array_search('accessory_reverse', $order);
     if ($orderByAccessory !== false) {
         $search->orderByPosition(Criteria::ASC);
         $order[$orderByAccessory] = 'given_id';
         $this->args->get('order')->setValue(implode(',', $order));
     }
     if ($orderByAccessoryReverse !== false) {
         $search->orderByPosition(Criteria::DESC);
         $order[$orderByAccessoryReverse] = 'given_id';
         $this->args->get('order')->setValue(implode(',', $order));
     }
     $accessories = $this->search($search);
     $this->accessoryIdList = array(0);
     $this->accessoryPosition = $this->accessoryId = array();
     foreach ($accessories as $accessory) {
         $accessoryProductId = $accessory->getAccessory();
         array_push($this->accessoryIdList, $accessoryProductId);
         $this->accessoryPosition[$accessoryProductId] = $accessory->getPosition();
         $this->accessoryId[$accessoryProductId] = $accessory->getId();
     }
     $receivedIdList = $this->getId();
     /* if an Id list is receive, loop will only match accessories from this list */
     if ($receivedIdList === null) {
         $this->args->get('id')->setValue(implode(',', $this->accessoryIdList));
     } else {
         $this->args->get('id')->setValue(implode(',', array_intersect($receivedIdList, $this->accessoryIdList)));
     }
     return parent::buildModelCriteria();
 }
예제 #2
0
 /**
  * Update accessory position
  */
 public function updateAccessoryPositionAction()
 {
     $accessory = AccessoryQuery::create()->findPk($this->getRequest()->get('accessory_id', null));
     return $this->genericUpdatePositionAction($accessory, TheliaEvents::PRODUCT_UPDATE_ACCESSORY_POSITION);
 }
예제 #3
0
파일: faker.php 프로젝트: hadesain/thelia
 Model\FeatureAvI18nQuery::create()->deleteAll();
 Model\AttributeQuery::create()->deleteAll();
 Model\AttributeI18nQuery::create()->deleteAll();
 Model\AttributeAvQuery::create()->deleteAll();
 Model\AttributeAvI18nQuery::create()->deleteAll();
 Model\CategoryQuery::create()->deleteAll();
 Model\CategoryI18nQuery::create()->deleteAll();
 Model\ProductQuery::create()->deleteAll();
 Model\ProductI18nQuery::create()->deleteAll();
 Model\CustomerQuery::create()->deleteAll();
 Model\AdminQuery::create()->deleteAll();
 Model\FolderQuery::create()->deleteAll();
 Model\FolderI18nQuery::create()->deleteAll();
 Model\ContentQuery::create()->deleteAll();
 Model\ContentI18nQuery::create()->deleteAll();
 Model\AccessoryQuery::create()->deleteAll();
 Model\ProductSaleElementsQuery::create()->deleteAll();
 Model\ProductPriceQuery::create()->deleteAll();
 Model\BrandQuery::create()->deleteAll();
 Model\BrandI18nQuery::create()->deleteAll();
 Model\ProductImageQuery::create()->deleteAll();
 Model\CategoryImageQuery::create()->deleteAll();
 Model\FolderImageQuery::create()->deleteAll();
 Model\ContentImageQuery::create()->deleteAll();
 Model\BrandImageQuery::create()->deleteAll();
 Model\ProductDocumentQuery::create()->deleteAll();
 Model\CategoryDocumentQuery::create()->deleteAll();
 Model\FolderDocumentQuery::create()->deleteAll();
 Model\ContentDocumentQuery::create()->deleteAll();
 Model\BrandDocumentQuery::create()->deleteAll();
 Model\CouponQuery::create()->deleteAll();
예제 #4
0
 /**
  * @depends testCloneAssociatedContent
  * @param ProductCloneEvent $event
  * @return ProductCloneEvent
  */
 public function testCloneAccessories(ProductCloneEvent $event)
 {
     // Call function to test
     $action = new Product();
     $action->cloneAccessories($event);
     // Get products' associated contents
     $originalProductAccessoryList = AccessoryQuery::create()->findByProductId($event->getOriginalProduct()->getId());
     $cloneProductAccessoryList = AccessoryQuery::create()->filterByProductId($event->getClonedProduct()->getId())->count();
     $this->assertEquals(count($originalProductAccessoryList), $cloneProductAccessoryList, 'There must be the same quantity of accessories');
     // Check clone product's accessories
     foreach ($originalProductAccessoryList as $originalProductAccessory) {
         $cloneProductAccessory = AccessoryQuery::create()->filterByProductId($event->getClonedProduct()->getId())->filterByPosition($originalProductAccessory->getPosition())->findOneByAccessory($originalProductAccessory->getAccessory());
         $this->assertInstanceOf('Thelia\\Model\\Accessory', $cloneProductAccessory, 'Instance of clone product accessory must be Thelia\\Model\\Accessory');
         $this->assertEquals($event->getClonedProduct()->getId(), $cloneProductAccessory->getProductId(), 'ProductID must be equal');
         $this->assertEquals($originalProductAccessory->getAccessory(), $cloneProductAccessory->getAccessory(), 'Accessory must be equal');
         $this->assertEquals($originalProductAccessory->getPosition(), $cloneProductAccessory->getPosition(), 'Position must be equal');
     }
     return $event;
 }
예제 #5
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Accessory::setDeleted()
  * @see Accessory::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(AccessoryTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildAccessoryQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
예제 #6
0
파일: Product.php 프로젝트: savvagee/thelia
 /**
  * Changes accessry position, selecting absolute ou relative change.
  *
  * @param ProductChangePositionEvent $event
  */
 public function updateAccessoryPosition(UpdatePositionEvent $event)
 {
     return $this->genericUpdatePosition(AccessoryQuery::create(), $event);
 }
예제 #7
0
파일: Product.php 프로젝트: shirone/thelia
 /**
  * Returns the number of related Accessory objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related Accessory objects.
  * @throws PropelException
  */
 public function countAccessoriesRelatedByAccessory(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collAccessoriesRelatedByAccessoryPartial && !$this->isNew();
     if (null === $this->collAccessoriesRelatedByAccessory || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collAccessoriesRelatedByAccessory) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getAccessoriesRelatedByAccessory());
         }
         $query = ChildAccessoryQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByProductRelatedByAccessory($this)->count($con);
     }
     return count($this->collAccessoriesRelatedByAccessory);
 }
예제 #8
0
 /**
  * @depends testAddAccessory
  */
 public function testRemoveAccessory(ProductModel $product)
 {
     $accessories = AccessoryQuery::create()->filterByProductId($product->getId())->find();
     $this->assertEquals(1, count($accessories));
     $currentAccessory = $accessories->getFirst();
     $event = new ProductDeleteAccessoryEvent($product, $currentAccessory->getAccessory());
     $event->setDispatcher($this->getDispatcher());
     $action = new Product();
     $action->removeAccessory($event);
     $this->assertEquals(0, AccessoryQuery::create()->filterByProductId($product->getId())->count());
     return $product;
 }
예제 #9
0
 /**
  * Changes accessry position, selecting absolute ou relative change.
  *
  * @param UpdatePositionEvent $event
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  * @return Object
  */
 public function updateAccessoryPosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     return $this->genericUpdatePosition(AccessoryQuery::create(), $event, $dispatcher);
 }
예제 #10
0
 /**
  * Performs an INSERT on the database, given a Accessory or Criteria object.
  *
  * @param mixed               $criteria Criteria or Accessory object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(AccessoryTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Accessory object
     }
     if ($criteria->containsKey(AccessoryTableMap::ID) && $criteria->keyContainsValue(AccessoryTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . AccessoryTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = AccessoryQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }