protected function getExistingObject() { $template = TemplateQuery::create()->findOneById($this->getRequest()->get('template_id', 0)); if (null !== $template) { $template->setLocale($this->getCurrentEditionLocale()); } return $template; }
protected function doAddToAllTemplates(FeatureModel $feature) { $templates = TemplateQuery::create()->find(); foreach ($templates as $template) { $feature_template = new FeatureTemplate(); if (null === FeatureTemplateQuery::create()->filterByFeature($feature)->filterByTemplate($template)->findOne()) { $feature_template->setFeature($feature)->setTemplate($template)->save(); } } }
protected function doAddToAllTemplates(AttributeModel $attribute) { $templates = TemplateQuery::create()->find(); foreach ($templates as $template) { $attribute_template = new AttributeTemplate(); if (null === AttributeTemplateQuery::create()->filterByAttribute($attribute)->filterByTemplate($template)->findOne()) { $attribute_template->setAttribute($attribute)->setTemplate($template)->save(); } } }
/** * Delete a product template entry * * @param \Thelia\Core\Event\Template\TemplateDeleteEvent $event */ public function delete(TemplateDeleteEvent $event) { if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) { // Check if template is used by a product $product_count = ProductQuery::create()->findByTemplateId($template->getId())->count(); if ($product_count <= 0) { $template->setDispatcher($event->getDispatcher())->delete(); } $event->setTemplate($template); $event->setProductCount($product_count); } }
public function preImport() { // Delete table before proceeding ProductQuery::create()->deleteAll(); CategoryQuery::create()->deleteAll(); FeatureTemplateQuery::create()->deleteAll(); AttributeTemplateQuery::create()->deleteAll(); TemplateQuery::create()->deleteAll(); CategoryImageQuery::create()->deleteAll(); CategoryDocumentQuery::create()->deleteAll(); CategoryAssociatedContentQuery::create()->deleteAll(); // Create T1 <-> T2 IDs correspondance tables $this->cat_corresp->reset(); $this->tpl_corresp->reset(); }
public function buildModelCriteria() { $search = TemplateQuery::create(); /* manage translations */ $this->configureI18nProcessing($search, array('NAME')); $id = $this->getId(); if (null !== $id) { $search->filterById($id, Criteria::IN); } $exclude = $this->getExclude(); if (null !== $exclude) { $search->filterById($exclude, Criteria::NOT_IN); } return $search; }
protected function buildForm() { $this->doBuilForm($this->translator->trans('The category title')); // Create countries and shipping modules list $templateList = [0 => ' ']; $list = TemplateQuery::create()->find(); // Get the current edition locale $locale = $this->getRequest()->getSession()->getAdminEditionLang()->getLocale(); /** @var \Thelia\Model\Template $item */ foreach ($list as $item) { $templateList[$item->getId()] = $item->setLocale($locale)->getName(); } asort($templateList); $templateList[0] = $this->translator->trans("None"); $this->formBuilder->add('id', 'hidden', ['constraints' => [new GreaterThan(array('value' => 0))]])->add('default_template_id', 'choice', ['choices' => $templateList, 'label' => $this->translator->trans('Default product template'), 'label_attr' => ['for' => 'price_offset_type', 'help' => $this->translator->trans('Select a default template for new products created in this category')], 'attr' => []]); // Add standard description fields, excluding title which is defined in parent class $this->addStandardDescFields(['title']); }
/** * Delete a product template entry * * @param \Thelia\Core\Event\Template\TemplateDeleteEvent $event * @throws \Exception */ public function delete(TemplateDeleteEvent $event) { if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) { // Check if template is used by a product $product_count = ProductQuery::create()->findByTemplateId($template->getId())->count(); if ($product_count <= 0) { $con = Propel::getWriteConnection(TemplateTableMap::DATABASE_NAME); $con->beginTransaction(); try { $template->setDispatcher($event->getDispatcher())->delete($con); // We have to also delete any reference of this template in category tables // We can't use a FK here, as the DefaultTemplateId column may be NULL // so let's take care of this. CategoryQuery::create()->filterByDefaultTemplateId($event->getTemplateId())->update(['DefaultTemplateId' => null], $con); $con->commit(); } catch (\Exception $ex) { $con->rollback(); throw $ex; } } $event->setTemplate($template); $event->setProductCount($product_count); } }
/** * Performs an INSERT on the database, given a Template or Criteria object. * * @param mixed $criteria Criteria or Template 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(TemplateTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Template object } if ($criteria->containsKey(TemplateTableMap::ID) && $criteria->keyContainsValue(TemplateTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . TemplateTableMap::ID . ')'); } // Set the correct dbName $query = TemplateQuery::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; }
public function buildModelCriteria() { $search = FeatureQuery::create(); /* manage translations */ $this->configureI18nProcessing($search); $id = $this->getId(); if (null !== $id) { $search->filterById($id, Criteria::IN); } $exclude = $this->getExclude(); if (null !== $exclude) { $search->filterById($exclude, Criteria::NOT_IN); } $visible = $this->getVisible(); if ($visible != BooleanOrBothType::ANY) { $search->filterByVisible($visible); } $product = $this->getProduct(); $template = $this->getTemplate(); $exclude_template = $this->getExcludeTemplate(); $this->useFeaturePosition = true; if (null !== $product) { // Find all template assigned to the products. $products = ProductQuery::create()->findById($product); // Ignore if the product cannot be found. if ($products !== null) { // Create template array if ($template == null) { $template = array(); } foreach ($products as $product) { $tpl_id = $product->getTemplateId(); if (!is_null($tpl_id)) { $template[] = $tpl_id; } } } // franck@cqfdev.fr - 05/12/2013 : if the given product has no template // or if the product cannot be found, do not return anything. if (empty($template)) { return null; } } if (!empty($template)) { // Join with feature_template table to get position $search->withColumn(FeatureTemplateTableMap::POSITION, 'position')->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN); $this->useFeaturePosition = false; } if (null !== $exclude_template) { $exclude_features = FeatureTemplateQuery::create()->filterByTemplateId($exclude_template)->select('feature_id')->find(); $search->filterById($exclude_features, Criteria::NOT_IN); } $title = $this->getTitle(); if (null !== $title) { //find all feature that match exactly this title and find with all locales. $features = FeatureI18nQuery::create()->filterByTitle($title, Criteria::LIKE)->select('id')->find(); if ($features) { $search->filterById($features, Criteria::IN); } } $orders = $this->getOrder(); foreach ($orders as $order) { switch ($order) { case "id": $search->orderById(Criteria::ASC); break; case "id_reverse": $search->orderById(Criteria::DESC); break; case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; case "alpha-reverse": $search->addDescendingOrderByColumn('i18n_TITLE'); break; case "manual": if ($this->useFeaturePosition) { $search->orderByPosition(Criteria::ASC); } else { $search->addAscendingOrderByColumn(FeatureTemplateTableMap::POSITION); } break; case "manual_reverse": if ($this->useFeaturePosition) { $search->orderByPosition(Criteria::DESC); } else { $search->addDescendingOrderByColumn(FeatureTemplateTableMap::POSITION); } break; } } return $search; }
/** * @depends testRemoveAccessory */ public function testSetProductTemplate(ProductModel $product) { $templateId = TemplateQuery::create()->select('id')->addAscendingOrderByColumn('RAND()')->findOne(); $currencyId = CurrencyQuery::create()->select('id')->addAscendingOrderByColumn('RAND()')->findOne(); $oldProductSaleElements = $product->getDefaultSaleElements(); $this->assertEquals("Thelia\\Model\\ProductSaleElements", get_class($oldProductSaleElements), "There is no default pse for this product"); $event = new ProductSetTemplateEvent($product, $templateId, $currencyId); $event->setDispatcher($this->getDispatcher()); $action = new Product(); $action->setProductTemplate($event); $updatedProduct = $event->getProduct(); $this->assertEquals($templateId, $updatedProduct->getTemplateId()); $productSaleElements = $updatedProduct->getProductSaleElementss(); $this->assertEquals(1, count($productSaleElements), "after setting a new template, only 1 product_sale_elements must be present"); /** @var \Thelia\Model\ProductSaleElements $newProductSaleElements */ $newProductSaleElements = $productSaleElements->getFirst(); $this->assertEquals($updatedProduct->getRef(), $newProductSaleElements->getRef(), sprintf("PSE ref must be %s", $updatedProduct->getRef())); $this->assertTrue($newProductSaleElements->getIsDefault(), 'new PSE must be the default one for this product'); $productPrice = $newProductSaleElements->getProductPrices()->getFirst(); $oldProductPrice = $oldProductSaleElements->getProductPrices()->getFirst(); $this->assertEquals($oldProductSaleElements->getWeight(), $newProductSaleElements->getWeight(), sprintf("->testSetProductTemplate new PSE weight must be %s", $oldProductSaleElements->getWeight())); $this->assertEquals($oldProductPrice->getPrice(), $productPrice->getPrice(), sprintf("->testSetProductTemplate price must be %s", $oldProductPrice->getPrice())); $this->assertEquals($oldProductPrice->getPromoPrice(), $productPrice->getPromoPrice(), sprintf("->testSetProductTemplate promo price must be %s", $oldProductPrice->getPromoPrice())); $this->assertEquals($oldProductPrice->getCurrencyId(), $productPrice->getCurrencyId(), sprintf("->testSetProductTemplate currency_id must be %s", $oldProductPrice->getCurrencyId())); return $updatedProduct; }
/** * Gets the number of ChildTemplate objects related by a many-to-many relationship * to the current object by way of the feature_template cross-reference table. * * @param Criteria $criteria Optional query object to filter the query * @param boolean $distinct Set to true to force count distinct * @param ConnectionInterface $con Optional connection object * * @return int the number of related ChildTemplate objects */ public function countTemplates($criteria = null, $distinct = false, ConnectionInterface $con = null) { if (null === $this->collTemplates || null !== $criteria) { if ($this->isNew() && null === $this->collTemplates) { return 0; } else { $query = ChildTemplateQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByFeature($this)->count($con); } } else { return count($this->collTemplates); } }
public function testCreateWithOptionalParametersAction() { $client = static::createClient(); $category = CategoryQuery::create()->addAscendingOrderByColumn('RAND()')->findOne(); $defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1); $taxRule = TaxRuleQuery::create()->findOneByIsDefault(1); $templateId = $category->getDefaultTemplateId(); if (null === $templateId) { $templateId = TemplateQuery::create()->addAscendingOrderByColumn('RAND()')->findOne()->getId(); } $product = ['ref' => uniqid('testCreateProduct'), 'locale' => 'en_US', 'title' => 'product create from api', 'description' => 'product description from api', 'default_category' => $category->getId(), 'visible' => 1, 'price' => '10', 'currency' => $defaultCurrency->getId(), 'tax_rule' => $taxRule->getId(), 'weight' => 10, 'brand_id' => 0, 'quantity' => 10, 'template_id' => $templateId]; $requestContent = json_encode($product); $servers = $this->getServerParameters(); $servers['CONTENT_TYPE'] = 'application/json'; $client->request('POST', '/api/products?&sign=' . $this->getSignParameter($requestContent), [], [], $servers, $requestContent); $this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201'); $content = json_decode($client->getResponse()->getContent(), true); $this->assertEquals('en_US', $content[0]['LOCALE']); $this->assertEquals(10, $content[0]['QUANTITY']); $this->assertEquals($templateId, $content[0]['TEMPLATE']); }
/** * Get the associated ChildTemplate object * * @param ConnectionInterface $con Optional Connection object. * @return ChildTemplate The associated ChildTemplate object. * @throws PropelException */ public function getTemplate(ConnectionInterface $con = null) { if ($this->aTemplate === null && $this->template_id !== null) { $this->aTemplate = ChildTemplateQuery::create()->findPk($this->template_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->aTemplate->addProducts($this); */ } return $this->aTemplate; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see Template::setDeleted() * @see Template::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(TemplateTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildTemplateQuery::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; } }
public function buildModelCriteria() { $search = AttributeQuery::create(); /* manage translations */ $this->configureI18nProcessing($search); $id = $this->getId(); if (null !== $id) { $search->filterById($id, Criteria::IN); } $exclude = $this->getExclude(); if (null !== $exclude) { $search->filterById($exclude, Criteria::NOT_IN); } $product = $this->getProduct(); $template = $this->getTemplate(); $excludeTemplate = $this->getExcludeTemplate(); $this->useAttributePosistion = true; if (null !== $product) { // Find all template assigned to the products. $products = ProductQuery::create()->findById($product); // Ignore if the product cannot be found. if ($products !== null) { // Create template array if ($template == null) { $template = array(); } /** @var ProductModel $product */ foreach ($products as $product) { $tplId = $product->getTemplateId(); if (!is_null($tplId)) { $template[] = $tplId; } } } // franck@cqfdev.fr - 05/12/2013 : if the given product has no template // or if the product cannot be found, do not return anything. if (empty($template)) { return null; } } if (!empty($template)) { // Join with feature_template table to get position $search->withColumn(AttributeTemplateTableMap::POSITION, 'position')->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN); $this->useAttributePosistion = false; } elseif (null !== $excludeTemplate) { // Join with attribute_template table to get position $excludeAttributes = AttributeTemplateQuery::create()->filterByTemplateId($excludeTemplate)->select('attribute_id')->find(); $search->filterById($excludeAttributes, Criteria::NOT_IN); } $orders = $this->getOrder(); foreach ($orders as $order) { switch ($order) { case "id": $search->orderById(Criteria::ASC); break; case "id_reverse": $search->orderById(Criteria::DESC); break; case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; case "alpha_reverse": $search->addDescendingOrderByColumn('i18n_TITLE'); break; case "manual": if ($this->useAttributePosistion) { $search->orderByPosition(Criteria::ASC); } else { $search->addAscendingOrderByColumn(AttributeTemplateTableMap::POSITION); } break; case "manual_reverse": if ($this->useAttributePosistion) { $search->orderByPosition(Criteria::DESC); } else { $search->addDescendingOrderByColumn(AttributeTemplateTableMap::POSITION); } break; } } return $search; }