Beispiel #1
0
 /**
  * @param    Product $product The product object to add.
  */
 protected function doAddProduct($product)
 {
     $productCategory = new ChildProductCategory();
     $productCategory->setProduct($product);
     $this->addProductCategory($productCategory);
     // set the back reference to this object directly as using provided method either results
     // in endless loop or in multiple relations
     if (!$product->getCategories()->contains($this)) {
         $foreignCollection = $product->getCategories();
         $foreignCollection[] = $this;
     }
 }
Beispiel #2
0
 public function updateDefaultCategory($defaultCategoryId)
 {
     // Allow uncategorized products (NULL instead of 0, to bypass delete cascade constraint)
     if ($defaultCategoryId <= 0) {
         $defaultCategoryId = NULL;
     }
     // Update the default category
     $productCategory = ProductCategoryQuery::create()->filterByProductId($this->getId())->filterByDefaultCategory(true)->findOne();
     if ($productCategory == null || $productCategory->getCategoryId() != $defaultCategoryId) {
         // Delete the old default category
         if ($productCategory !== null) {
             $productCategory->delete();
         }
         // Add the new default category
         $productCategory = new ProductCategory();
         $productCategory->setProduct($this)->setCategoryId($defaultCategoryId)->setDefaultCategory(true)->save();
     }
 }
Beispiel #3
0
 /**
  * Filter the query by a related \Thelia\Model\ProductCategory object
  *
  * @param \Thelia\Model\ProductCategory|ObjectCollection $productCategory  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCategoryQuery The current query, for fluid interface
  */
 public function filterByProductCategory($productCategory, $comparison = null)
 {
     if ($productCategory instanceof \Thelia\Model\ProductCategory) {
         return $this->addUsingAlias(CategoryTableMap::ID, $productCategory->getCategoryId(), $comparison);
     } elseif ($productCategory instanceof ObjectCollection) {
         return $this->useProductCategoryQuery()->filterByPrimaryKeys($productCategory->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByProductCategory() only accepts arguments of type \\Thelia\\Model\\ProductCategory or Collection');
     }
 }
Beispiel #4
0
 public function addCategory(ProductAddCategoryEvent $event)
 {
     if (ProductCategoryQuery::create()->filterByProduct($event->getProduct())->filterByCategoryId($event->getCategoryId())->count() <= 0) {
         $productCategory = new ProductCategory();
         $productCategory->setProduct($event->getProduct())->setCategoryId($event->getCategoryId())->setDefaultCategory(false)->save();
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database. In some cases you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by find*()
  * and findPk*() calls.
  *
  * @param \Thelia\Model\ProductCategory $obj A \Thelia\Model\ProductCategory object.
  * @param string $key             (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if (null === $key) {
             $key = serialize(array((string) $obj->getProductId(), (string) $obj->getCategoryId()));
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
 /**
  * Exclude object from result
  *
  * @param   ChildProductCategory $productCategory Object to remove from the list of results
  *
  * @return ChildProductCategoryQuery The current query, for fluid interface
  */
 public function prune($productCategory = null)
 {
     if ($productCategory) {
         $this->addCond('pruneCond0', $this->getAliasedColName(ProductCategoryTableMap::PRODUCT_ID), $productCategory->getProductId(), Criteria::NOT_EQUAL);
         $this->addCond('pruneCond1', $this->getAliasedColName(ProductCategoryTableMap::CATEGORY_ID), $productCategory->getCategoryId(), Criteria::NOT_EQUAL);
         $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
     }
     return $this;
 }