Exemplo n.º 1
0
 public static function create($conn = null, $class = null)
 {
     $q = new ProductQuery($conn);
     $q->addSelect('p.id, p.reference, p.description, p.price')->addSelect($q->quantity_col)->addSelect($q->sold_col)->from("Product p, p.Items i, i.Common inv")->orderBy('p.reference asc')->groupBy('p.id');
     //    echo $q->getSqlQuery();
     return $q;
 }
Exemplo n.º 2
0
 /**
  * Returns a new ProductQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   ProductQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return ProductQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof ProductQuery) {
         return $criteria;
     }
     $query = new ProductQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 /**
  *
  * @Route("/show", name="show_product")
  */
 public function showAction($id)
 {
     $product = ProductQuery::create()->findPk($id);
     if (!$product) {
         throw $this->createNotFoundException('No product found for id ' . $id);
     }
 }
Exemplo n.º 4
0
 public function listProductAction()
 {
     $request = $this->getRequest();
     $key = $request->getParam('product_id');
     $product = ProductQuery::create()->findOneByEntityId($key);
     $this->view->pagetitle = $product->getName();
     $this->view->product = $product;
 }
 protected function _init()
 {
     parent::_init();
     // create a filterquery
     $fq = $this->createFilterQuery();
     $fq->setKey('maxprice');
     $fq->setQuery('price:[1 TO 300]');
     // and add it
     $this->addFilterQuery($fq);
 }
Exemplo n.º 6
0
 public function executeIndex(sfWebRequest $request)
 {
     $namespace = $request->getParameter('searchNamespace');
     $search = $this->getUser()->getAttribute('search', null, $namespace);
     $sort = $this->getUser()->getAttribute('sort', array('reference', 'desc'), $namespace);
     $page = $this->getUser()->getAttribute('page', 1, $namespace);
     $maxResults = $this->getUser()->getPaginationMaxResults();
     $q = ProductQuery::create()->search($search)->orderBy("{$sort['0']} {$sort['1']}, reference {$sort['1']}");
     // totals
     $this->quantity = $q->total('quantity');
     $this->sold = $q->total('sold');
     $this->pager = new sfDoctrinePager('Product', $maxResults);
     $this->pager->setQuery($q);
     $this->pager->setPage($page);
     $this->pager->init();
     $this->getUser()->setAttribute('page', $request->getParameter('page'));
     $this->sort = $sort;
 }
Exemplo n.º 7
0
 /**
  * 
  * @param type $productId
  */
 public function fromProductId($productId)
 {
     $product = ProductQuery::create()->findPk($productId);
     $this->fromProduct($product);
 }
Exemplo n.º 8
0
 /**
  * Get the associated Product object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return Product The associated Product object.
  * @throws PropelException
  */
 public function getProduct(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aProduct === null && $this->product_id !== null && $doQuery) {
         $this->aProduct = ProductQuery::create()->findPk($this->product_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aProduct->addUserProducts($this);
            */
     }
     return $this->aProduct;
 }
Exemplo n.º 9
0
 /**
  * Gets the number of Product objects related by a many-to-many relationship
  * to the current object by way of the product_plugin cross-reference table.
  *
  * @param Criteria $criteria Optional query object to filter the query
  * @param boolean $distinct Set to true to force count distinct
  * @param PropelPDO $con Optional connection object
  *
  * @return int the number of related Product objects
  */
 public function countProducts($criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collProducts || null !== $criteria) {
         if ($this->isNew() && null === $this->collProducts) {
             return 0;
         } else {
             $query = ProductQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByPlugin($this)->count($con);
         }
     } else {
         return count($this->collProducts);
     }
 }
Exemplo n.º 10
0
 protected function init()
 {
     parent::init();
     // create a filterquery
     $this->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]');
 }
Exemplo n.º 11
0
                    $op = OrganizationProductQuery::create()->filterByProductId($id)->filterByOrganizationId($relation['id'])->findOne();
                    $op->setExpires($relation['expires']);
                    $op->save();
                }
                ok($res);
            } catch (Exception $e) {
                error('io-error', $e->getMessage());
            }
        } else {
            return error('unknown-product', 'Product not found');
        }
    });
});
$app->delete('/products/:id/organizations', function ($id) use($app) {
    if_is_admin(function () use($app, $id) {
        $product = ProductQuery::create()->findPk($id);
        if ($product) {
            $data = json_decode($app->request()->getBody(), true);
            foreach ($data as $orgid) {
                $org = OrganizationQuery::create()->findPk($orgid);
                if ($org) {
                    $product->removeOrganization($org);
                }
            }
            try {
                $product->save();
                ok();
            } catch (Exception $e) {
                error('io-error', $e->getMessage());
            }
        } else {
Exemplo n.º 12
0
 /**
  * Returns the number of related Product objects.
  *
  * @param Criteria $criteria
  * @param boolean $distinct
  * @param PropelPDO $con
  * @return int             Count of related Product objects.
  * @throws PropelException
  */
 public function countProducts(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     $partial = $this->collProductsPartial && !$this->isNew();
     if (null === $this->collProducts || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collProducts) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getProducts());
         }
         $query = ProductQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByCategory($this)->count($con);
     }
     return count($this->collProducts);
 }
Exemplo n.º 13
0
 protected function setUp()
 {
     \ProductQuery::create()->deleteAll();
     \ProductI18nQuery::create()->deleteAll();
 }
Exemplo n.º 14
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ProductQuery::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;
     }
 }
Exemplo n.º 15
0
 /**
  * @param $cart
  *
  * @return array
  */
 public function productArray(Application_Model_Zendshop_Cart $cart)
 {
     $productIds = $cart->getProductIds();
     if ($productIds) {
         $cartProducts = ProductQuery::create()->filterByPrimaryKeys($productIds)->find();
     } else {
         $cartProducts = false;
     }
     $data = array();
     if (!empty($cartProducts)) {
         foreach ($cartProducts as $cartProduct) {
             $productData = array();
             $productData['image'] = $cartProduct->getImage();
             $productData['name'] = $cartProduct->getName();
             $productData['price'] = $cartProduct->getPrice();
             $cartItems = $cart->getCartItems();
             $productData['quantity'] = $cartItems[$cartProduct->getEntityId()]->getQuantity();
             $productData['entity_id'] = $cartProduct->getEntityId();
             $data[$cartProduct->getEntityId()] = $productData;
         }
     }
     return $data;
 }