/** * * @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); } }
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; }
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; }
/** * * @param type $productId */ public function fromProductId($productId) { $product = ProductQuery::create()->findPk($productId); $this->fromProduct($product); }
/** * 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; }
/** * 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); } }
$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 {
/** * 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); }
protected function setUp() { \ProductQuery::create()->deleteAll(); \ProductI18nQuery::create()->deleteAll(); }
/** * 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; } }
/** * @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; }