本文整理汇总了PHP中Thelia\Model\ProductQuery::create方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductQuery::create方法的具体用法?PHP ProductQuery::create怎么用?PHP ProductQuery::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thelia\Model\ProductQuery
的用法示例。
在下文中一共展示了ProductQuery::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cartFormAfterBuild
/**
* Add fields for attribute values selection in our own way (since the product on has its default PSE, it has
* no attributes as far as Thelia is concerned, but we want it to have all of its template's attributes).
*
* @param TheliaFormEvent $event
*/
public function cartFormAfterBuild(TheliaFormEvent $event)
{
$sessionLocale = null;
$session = $this->request->getSession();
if ($session !== null) {
$sessionLang = $session->getLang();
if ($sessionLang !== null) {
$sessionLocale = $sessionLang->getLocale();
}
}
$product = ProductQuery::create()->findPk($this->request->getProductId());
if ($product === null || $product->getTemplate() === null) {
return;
}
$productAttributes = AttributeQuery::create()->filterByTemplate($product->getTemplate())->find();
/** @var Attribute $productAttribute */
foreach ($productAttributes as $productAttribute) {
$attributeValues = AttributeAvQuery::create()->findByAttributeId($productAttribute->getId());
$choices = [];
/** @var AttributeAv $attributeValue */
foreach ($attributeValues as $attributeValue) {
if ($sessionLocale !== null) {
$attributeValue->setLocale($sessionLocale);
}
$choices[$attributeValue->getId()] = $attributeValue->getTitle();
}
$event->getForm()->getFormBuilder()->add(static::LEGACY_PRODUCT_ATTRIBUTE_FIELD_PREFIX . $productAttribute->getId(), 'choice', ['choices' => $choices, 'required' => true]);
}
}
示例2: checkDuplicateRef
public function checkDuplicateRef($value, ExecutionContextInterface $context)
{
$count = ProductQuery::create()->filterByRef($value)->count();
if ($count > 0) {
$context->addViolation(Translator::getInstance()->trans("A product with reference %ref already exists. Please choose another reference.", array('%ref' => $value)));
}
}
示例3: getDelayForProduct
/**
* @param $productId
* @return array
*/
public function getDelayForProduct($productId)
{
$delay = ProductDelayQuery::create()->filterByProductId($productId)->findOneOrCreate();
$defaultDelay = (new ProductDelay())->getDefaultValue();
$product = ProductQuery::create()->findOneById($productId);
if (!$product) {
return null;
}
$quantity = $this->productHasQuantity($product);
if (true === $quantity) {
$delayMin = $delay->getDeliveryDelayMin() ? $delay->getDeliveryDelayMin() : $defaultDelay->getDeliveryDelayMin();
$delayMax = $delay->getDeliveryDelayMax() ? $delay->getDeliveryDelayMax() : $defaultDelay->getDeliveryDelayMax();
} else {
$delayMin = $delay->getRestockDelayMin() ? $delay->getRestockDelayMin() : $defaultDelay->getRestockDelayMin();
$delayMax = $delay->getRestockDelayMax() ? $delay->getRestockDelayMax() : $defaultDelay->getRestockDelayMax();
}
$startDate = date("Y-m-d");
$delivery["deliveryDateStart"] = null;
if (null !== $delay->getDeliveryDateStart() && time() < strtotime($delay->getDeliveryDateStart())) {
$startDate = $delivery["deliveryDateStart"] = $delay->getDeliveryDateStart();
}
$delivery["deliveryType"] = $delay->getDeliveryType();
$delivery["deliveryMin"] = $this->computeDeliveryDate($startDate, $delayMin);
$delivery["deliveryMax"] = $this->computeDeliveryDate($startDate, $delayMax);
return $delivery;
}
示例4: parseResults
public function parseResults(LoopResult $loopResult)
{
$loopResult = parent::parseResults($loopResult);
/** @var LoopResultRow $loopResultRow */
foreach ($loopResult as $loopResultRow) {
// do nothing if no count is present (simple mode)
if ($loopResultRow->get('PSE_COUNT') === null) {
continue;
}
$product = ProductQuery::create()->findPk($loopResultRow->get('ID'));
// do nothing if we don't use legacy attributes for this product
$productCheckEvent = new ProductCheckEvent($product->getId());
$this->dispatcher->dispatch(LegacyProductAttributesEvents::PRODUCT_CHECK_LEGACY_ATTRIBUTES_APPLY, $productCheckEvent);
if (!$productCheckEvent->getResult()) {
continue;
}
// nothing to do if the product has no template (and thus no attributes)
if ($product->getTemplate() === null) {
continue;
}
$virtualPseCount = 1;
foreach ($product->getTemplate()->getAttributes() as $attribute) {
$virtualPseCount *= $attribute->countAttributeAvs();
}
$loopResultRow->set('PSE_COUNT', $virtualPseCount);
}
return $loopResult;
}
示例5: testQuery
public function testQuery()
{
new Translator(new Container());
$export = new ProductSEOExport(new Container());
$data = $export->buildData(Lang::getDefaultLanguage());
$keys = ["ref", "visible", "product_title", "url", "page_title", "meta_description", "meta_keywords"];
sort($keys);
$rawData = $data->getData();
$max = count($rawData);
/**
* If there's more that 50 entries,
* just pick 50, it would be faster and as tested as if we test 1000 entries.
*/
if ($max > 50) {
$max = 50;
}
for ($i = 0; $i < $max; ++$i) {
$row = $rawData[$i];
$rowKeys = array_keys($row);
$this->assertTrue(sort($rowKeys));
$this->assertEquals($keys, $rowKeys);
$product = ProductQuery::create()->findOneByRef($row["ref"]);
$this->assertNotNull($product);
$this->assertEquals($product->getVisible(), $row["visible"]);
$this->assertEquals($product->getTitle(), $row["product_title"]);
$this->assertEquals($product->getMetaTitle(), $row["page_title"]);
$this->assertEquals($product->getMetaDescription(), $row["meta_description"]);
$this->assertEquals($product->getMetaKeywords(), $row["meta_keywords"]);
$this->assertEquals($product->getRewrittenUrl("en_US"), $row["url"]);
}
}
示例6: testCreate
public function testCreate()
{
// get a product
$product = ProductQuery::create()->findOne();
// simple
$event = new MetaDataCreateOrUpdateEvent();
$event->setMetaKey('test')->setElementKey(get_class($product))->setElementId($product->getId())->setValue('test')->setDispatcher($this->dispatcher);
$action = new MetaData();
$action->createOrUpdate($event);
$created = $event->getMetaData();
$this->assertInstanceOf('Thelia\\Model\\MetaData', $created);
$this->assertFalse($created->isNew());
$this->assertEquals('test', $created->getMetaKey());
$this->assertEquals(get_class($product), $created->getElementKey());
$this->assertEquals($product->getId(), $created->getElementId());
$this->assertEquals('test', $created->getValue());
$this->assertEquals(false, $created->getIsSerialized());
// complex
$event = new MetaDataCreateOrUpdateEvent();
$event->setMetaKey('test2')->setElementKey(get_class($product))->setElementId($product->getId())->setValue(array("fr_FR" => "bonjour", "en_US" => "Hello"))->setDispatcher($this->dispatcher);
$action = new MetaData();
$action->createOrUpdate($event);
$created = $event->getMetaData();
$this->assertInstanceOf('Thelia\\Model\\MetaData', $created);
$this->assertFalse($created->isNew());
$this->assertEquals('test2', $created->getMetaKey());
$this->assertEquals(get_class($product), $created->getElementKey());
$this->assertEquals($product->getId(), $created->getElementId());
$this->assertEquals(array("fr_FR" => "bonjour", "en_US" => "Hello"), $created->getValue());
$this->assertEquals(true, $created->getIsSerialized());
return $product;
}
示例7: onMainBodyBottom
public function onMainBodyBottom(HookRenderEvent $event)
{
$options = array();
switch ($this->getRequest()->get('_view')) {
// Category page viewed
case 'category':
$categoryId = $this->getRequest()->get('category_id');
$defaultCategory = CategoryQuery::create()->findPk($categoryId);
$options[] = array('setEcommerceView', false, false, $defaultCategory->getTitle());
break;
// Product detail page viewed
// Product detail page viewed
case 'product':
$productId = $this->getRequest()->getProductId();
$product = ProductQuery::create()->findPk($productId);
if ($defaultCategoryId = $product->getDefaultCategoryId()) {
$defaultCategory = CategoryQuery::create()->findPk($defaultCategoryId);
}
$options[] = array('setEcommerceView', $product->getRef() ? $product->getRef() : $product->getId(), $product->getTitle(), isset($defaultCategory) ? $defaultCategory->getTitle() : false, false);
break;
}
if ($code = $this->generateTrackingCode($options)) {
$event->add($code);
}
}
示例8: checkRefDifferent
public function checkRefDifferent($value, ExecutionContextInterface $context)
{
$originalRef = ProductQuery::create()->filterByRef($value, Criteria::EQUAL)->count();
if ($originalRef !== 0) {
$context->addViolation($this->translator->trans('This product reference is already assigned to another product.'));
}
}
示例9: checkProduct
public function checkProduct($value, ExecutionContextInterface $context)
{
$product = ProductQuery::create()->findPk($value);
if (is_null($product) || $product->getVisible() == 0) {
throw new ProductNotFoundException(sprintf(Translator::getInstance()->trans("this product id does not exists : %d"), $value));
}
}
示例10: getPrices
/**
* Get the untaxed price and, if the product is in sale, promo price of a product.
*
* @param ProductGetPricesEvent $event
*/
public function getPrices(ProductGetPricesEvent $event)
{
$product = ProductQuery::create()->findPk($event->getProductId());
if (null === $product) {
throw new \InvalidArgumentException('No product given');
}
$currency = CurrencyQuery::create()->findPk($event->getCurrencyId());
if (null === $currency) {
$currency = CurrencyQuery::create()->findOneByByDefault(true);
}
// get the base prices given in the event
// or, by default, the prices of the product's default PSE
if (null !== $event->getBasePrices()) {
$price = $event->getBasePrices()->getPrice();
$promoPrice = $event->getBasePrices()->getPromoPrice();
} else {
$prices = $product->getDefaultSaleElements()->getPricesByCurrency($currency);
$price = $prices->getPrice();
$promoPrice = $prices->getPromoPrice();
}
// adjust the prices with the configured price delta from legacy attributes
$legacyProductAttributeValues = LegacyProductAttributeValueQuery::create()->filterByProductId($product->getId())->filterByAttributeAvId(array_values($event->getLegacyProductAttributes()), Criteria::IN)->find();
/** @var LegacyProductAttributeValue $legacyProductAttributeValue */
foreach ($legacyProductAttributeValues as $legacyProductAttributeValue) {
$legacyProductAttributeValuePrice = $legacyProductAttributeValue->getPriceForCurrency($event->getCurrencyId());
if ($legacyProductAttributeValuePrice === null) {
continue;
}
$price += $legacyProductAttributeValuePrice->getDelta();
$promoPrice += $legacyProductAttributeValuePrice->getDelta();
}
$event->setPrices(new ProductPriceTools($price, $promoPrice));
}
示例11: find
public function find(FindViewEvent $event)
{
$objectType = $event->getObjectType();
$objectId = $event->getObjectId();
// Try to find a direct match. A view is defined for the object.
if (null !== ($viewObj = ViewQuery::create()->filterBySourceId($objectId)->findOneBySource($objectType))) {
$viewName = $viewObj->getView();
if (!empty($viewName)) {
$event->setView($viewName)->setViewObject($viewObj);
return;
}
}
$foundView = $sourceView = null;
if ($objectType == 'category') {
$foundView = $this->searchInParents($objectId, $objectType, CategoryQuery::create(), false, $sourceView);
} elseif ($objectType == 'folder') {
$foundView = $this->searchInParents($objectId, $objectType, FolderQuery::create(), false, $sourceView);
} elseif ($objectType == 'product') {
if (null !== ($product = ProductQuery::create()->findPk($objectId))) {
$foundView = $this->searchInParents($product->getDefaultCategoryId(), 'category', CategoryQuery::create(), true, $sourceView);
}
} elseif ($objectType == 'content') {
if (null !== ($content = ContentQuery::create()->findPk($objectId))) {
$foundView = $this->searchInParents($content->getDefaultFolderId(), 'folder', FolderQuery::create(), true, $sourceView);
}
}
$event->setView($foundView)->setViewObject($sourceView);
}
示例12: getData
public function getData()
{
$locale = $this->language->getLocale();
$urlJoin = new Join(ProductTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
$productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
$query = ProductQuery::create()->addSelfSelectColumns()->addJoinObject($urlJoin, 'rewriting_url_join')->addJoinCondition('rewriting_url_join', RewritingUrlTableMap::VIEW_LOCALE . ' = ?', $locale, null, \PDO::PARAM_STR)->addJoinCondition('rewriting_url_join', RewritingUrlTableMap::VIEW . ' = ?', (new Product())->getRewrittenUrlViewName(), null, \PDO::PARAM_STR)->addJoinCondition('rewriting_url_join', 'ISNULL(' . RewritingUrlTableMap::REDIRECTED . ')')->addJoinObject($productJoin, 'product_join')->addJoinCondition('product_join', ProductI18nTableMap::LOCALE . ' = ?', $locale, null, \PDO::PARAM_STR)->addAsColumn('product_i18n_TITLE', ProductI18nTableMap::TITLE)->addAsColumn('product_seo_TITLE', ProductI18nTableMap::META_TITLE)->addAsColumn('product_seo_META_DESCRIPTION', ProductI18nTableMap::META_DESCRIPTION)->addAsColumn('product_seo_META_KEYWORDS', ProductI18nTableMap::META_KEYWORDS)->addAsColumn('product_URL', RewritingUrlTableMap::URL);
return $query;
}
示例13: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$currency = CurrencyQuery::create()->filterByCode('EUR')->findOne();
// Find a product
$this->freeProduct = ProductQuery::create()->findOne();
$this->originalPrice = $this->freeProduct->getDefaultSaleElements()->getPricesByCurrency($currency)->getPrice();
$this->originalPromo = $this->freeProduct->getDefaultSaleElements()->getPromo();
$this->freeProduct->getDefaultSaleElements()->setPromo(false)->save();
}
示例14: buildDataSet
/**
* @param Lang $lang
* @return array|\Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function buildDataSet(Lang $lang)
{
$locale = $this->locale = $lang->getLocale();
$query = ProductQuery::create();
$urlJoin = new Join(ProductTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
$productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
$query->addJoinObject($urlJoin, "rewriting_url_join")->addJoinCondition("rewriting_url_join", RewritingUrlTableMap::VIEW_LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addJoinCondition("rewriting_url_join", RewritingUrlTableMap::VIEW . " = ?", (new Product())->getRewrittenUrlViewName(), null, \PDO::PARAM_STR)->addJoinCondition("rewriting_url_join", "ISNULL(" . RewritingUrlTableMap::REDIRECTED . ")")->addJoinObject($productJoin, "product_join")->addJoinCondition("product_join", ProductI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR);
$query->addAsColumn("product_i18n_TITLE", ProductI18nTableMap::TITLE)->addAsColumn("product_REF", ProductTableMap::REF)->addAsColumn("product_VISIBLE", ProductTableMap::VISIBLE)->addAsColumn("product_seo_TITLE", ProductI18nTableMap::META_TITLE)->addAsColumn("product_seo_META_DESCRIPTION", ProductI18nTableMap::META_DESCRIPTION)->addAsColumn("product_seo_META_KEYWORDS", ProductI18nTableMap::META_KEYWORDS)->addAsColumn("product_URL", RewritingUrlTableMap::URL)->select(["product_REF", "product_VISIBLE", "product_i18n_TITLE", "product_URL", "product_seo_TITLE", "product_seo_META_DESCRIPTION", "product_seo_META_KEYWORDS"]);
return $query;
}
示例15: countAllProducts
/**
*
* count all products for current category and sub categories
*
* /!\ the number of queries is exponential, use it with caution
*
* @return int
*/
public function countAllProducts()
{
$children = CategoryQuery::findAllChild($this->getId());
array_push($children, $this);
$countProduct = 0;
foreach ($children as $child) {
$countProduct += ProductQuery::create()->filterByCategory($child)->count();
}
return $countProduct;
}