本文整理汇总了PHP中Thelia\Model\CategoryQuery类的典型用法代码示例。如果您正苦于以下问题:PHP CategoryQuery类的具体用法?PHP CategoryQuery怎么用?PHP CategoryQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CategoryQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildArray
public function buildArray()
{
$id = $this->getCategory();
$visible = $this->getVisible();
$search = CategoryQuery::create();
$this->configureI18nProcessing($search, array('TITLE'));
$search->filterById($id);
if ($visible !== BooleanOrBothType::ANY) {
$search->filterByVisible($visible);
}
$results = array();
$ids = array();
do {
$category = $search->findOne();
if ($category != null) {
$results[] = array("ID" => $category->getId(), "TITLE" => $category->getVirtualColumn('i18n_TITLE'), "URL" => $category->getUrl($this->locale), "LOCALE" => $this->locale);
$parent = $category->getParent();
if ($parent > 0) {
// Prevent circular refererences
if (in_array($parent, $ids)) {
throw new \LogicException(sprintf("Circular reference detected in category ID=%d hierarchy (category ID=%d appears more than one times in path)", $id, $parent));
}
$ids[] = $parent;
$search = CategoryQuery::create();
$this->configureI18nProcessing($search, array('TITLE'));
$search->filterById($parent);
if ($visible != BooleanOrBothType::ANY) {
$search->filterByVisible($visible);
}
}
}
} while ($category != null && $parent > 0);
// Reverse list and build the final result
return array_reverse($results);
}
示例2: 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);
}
}
示例3: 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);
}
示例4: getRandomCategory
/**
* @return \Thelia\Model\Category
*/
protected function getRandomCategory()
{
$category = CategoryQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
if (null === $category) {
$this->fail('use fixtures before launching test, there is no category in database');
}
return $category;
}
示例5: buildCategoryTree
protected function buildCategoryTree($parent, $visible, $level, $previousLevel, $maxLevel, $exclude, &$resultsList)
{
if ($level > $maxLevel) {
return;
}
if ($this->categories === null) {
$search = CategoryQuery::create();
$this->configureI18nProcessing($search, array('TITLE'));
if ($visible !== BooleanOrBothType::ANY) {
$search->filterByVisible($visible);
}
if ($exclude != null) {
$search->filterById($exclude, Criteria::NOT_IN);
}
$orders = $this->getOrder();
foreach ($orders as $order) {
switch ($order) {
case "position":
$search->orderByPosition(Criteria::ASC);
break;
case "position_reverse":
$search->orderByPosition(Criteria::DESC);
break;
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;
}
}
$results = $search->find();
$returnUrl = $this->getReturnUrl();
$this->categories = $this->container->get('category.cache.service')->getCategoryTree();
foreach ($results as $result) {
$row = array_merge($this->categories[$result->getParent()][$result->getId()], ["ID" => $result->getId(), "TITLE" => $result->getVirtualColumn('i18n_TITLE'), "PARENT" => $result->getParent(), "VISIBLE" => $result->getVisible() ? "1" : "0"]);
if ($returnUrl) {
$row['URL'] = $result->getUrl($this->locale);
}
$this->categories[$result->getParent()][$result->getId()] = $row;
}
}
if (isset($this->categories[$parent])) {
foreach ($this->categories[$parent] as $category) {
$row = $category;
$row['LEVEL'] = $level;
$row['PREV_LEVEL'] = $previousLevel;
$resultsList[] = $row;
$this->buildCategoryTree($row['ID'], $visible, 1 + $level, $level, $maxLevel, $exclude, $resultsList);
}
}
}
示例6: getCategoriesIdArray
private function getCategoriesIdArray()
{
$categories = CategoryQuery::create()->select("id")->find()->toArray();
$ids = [];
foreach ($categories as $category) {
$ids[$category] = $category;
}
return $ids;
}
示例7: getCategoriesIdArray
private function getCategoriesIdArray()
{
$categories = CategoryQuery::create()->find();
$ids = [];
foreach ($categories as $category) {
$ids[] = $category->getId();
}
return $ids;
}
示例8: generate
public function generate()
{
$categories = [];
$categoryQuery = CategoryQuery::create();
$categoryQuery->withColumn('(SELECT COUNT(*) FROM category ChildCategory WHERE ChildCategory.parent=category.id)', 'ChildCount')->withColumn('(SELECT COUNT(*) FROM product_category WHERE product_category.category_id=category.id)', 'ProductCount');
$results = $categoryQuery->find();
foreach ($results as $result) {
$categories[$result->getParent()][$result->getId()] = ['ID' => $result->getId(), 'PARENT' => $result->getParent(), 'VISIBLE' => $result->getVisible() ? "1" : "0", 'CHILD_COUNT' => $result->getVirtualColumn('ChildCount'), 'PRODUCT_COUNT' => $result->getVirtualColumn('ProductCount')];
}
$this->cache->save('category.tree', $categories);
return $categories;
}
示例9: trackOrder
public function trackOrder(OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$order = $event->getPlacedOrder();
$taxTotal = 0;
foreach ($order->getOrderProducts() as $orderProduct) {
$product = ProductQuery::create()->findPk($orderProduct->getVirtualColumn('product_id'));
$defaultCategory = CategoryQuery::create()->findPk($product->getDefaultCategoryId());
$taxTotal += $orderProduct->getVirtualColumn('TOTAL_TAX');
$this->tracker->addEcommerceItem($orderProduct->getProductSaleElementsRef() || $orderProduct->getProductRef() || $orderProduct->getId() || $orderProduct->getProductSaleElementsId(), $orderProduct->getTitle(), $defaultCategory->getTitle(), $orderProduct->getPrice(), $orderProduct->getQuantity());
}
$this->tracker->doTrackEcommerceOrder($order->getRef(), $order->getTotalAmount($taxTotal, true, true), $order->getTotalAmount($taxTotal, false, true), $taxTotal, $order->getPostage() + $order->getPostageTax(), $order->getDiscount());
}
示例10: testSearchById
public function testSearchById()
{
$category = CategoryQuery::create()->findOne();
if (null === $category) {
$category = new \Thelia\Model\Category();
$category->setParent(0);
$category->setVisible(1);
$category->setTitle('foo');
$category->save();
}
$otherParameters = array("visible" => "*");
$this->baseTestSearchById($category->getId(), $otherParameters);
}
示例11: buildModelCriteria
public function buildModelCriteria()
{
$query = CategoryQuery::create();
if ($this->getCategoryId()) {
$query->filterById($this->getCategoryId());
}
$this->configureI18nProcessing($query, array('TITLE'));
$taxonomyJoin = new Join();
$taxonomyJoin->addExplicitCondition(CategoryTableMap::TABLE_NAME, 'ID', null, GoogleshoppingTaxonomyTableMap::TABLE_NAME, 'THELIA_CATEGORY_ID', 'taxonomy');
$taxonomyJoin->setJoinType(Criteria::JOIN);
$query->addJoinObject($taxonomyJoin, 'taxonomy_join')->addJoinCondition('taxonomy_join', 'taxonomy.lang_id = ' . $this->getLangId())->withColumn('taxonomy.google_category', 'google_category')->addAscendingOrderByColumn('i18n_TITLE');
return $query;
}
示例12: buildCategoryTree
protected function buildCategoryTree($parent, $visible, $level, $previousLevel, $max_level, $exclude, &$resultsList)
{
if ($level > $max_level) {
return;
}
$search = CategoryQuery::create();
$this->configureI18nProcessing($search, array('TITLE'));
$search->filterByParent($parent);
if ($visible !== BooleanOrBothType::ANY) {
$search->filterByVisible($visible);
}
if ($exclude != null) {
$search->filterById($exclude, Criteria::NOT_IN);
}
$orders = $this->getOrder();
foreach ($orders as $order) {
switch ($order) {
case "position":
$search->orderByPosition(Criteria::ASC);
break;
case "position_reverse":
$search->orderByPosition(Criteria::DESC);
break;
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;
}
}
$results = $search->find();
$need_count_child = $this->getNeedCountChild();
foreach ($results as $result) {
$row = array("ID" => $result->getId(), "TITLE" => $result->getVirtualColumn('i18n_TITLE'), "PARENT" => $result->getParent(), "URL" => $result->getUrl($this->locale), "VISIBLE" => $result->getVisible() ? "1" : "0", "LEVEL" => $level, 'PREV_LEVEL' => $previousLevel);
if ($need_count_child) {
$row['CHILD_COUNT'] = $result->countChild();
}
$resultsList[] = $row;
$this->buildCategoryTree($result->getId(), $visible, 1 + $level, $level, $max_level, $exclude, $resultsList);
}
}
示例13: testCreateAction
public function testCreateAction()
{
$client = static::createClient();
$category = CategoryQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
$taxRule = TaxRuleQuery::create()->findOneByIsDefault(1);
$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];
$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']);
return $content['0']['ID'];
}
示例14: create
/**
* Create a new product entry
*
* @param \Thelia\Core\Event\Product\ProductCreateEvent $event
*/
public function create(ProductCreateEvent $event)
{
$product = new ProductModel();
$product->setDispatcher($event->getDispatcher())->setRef($event->getRef())->setLocale($event->getLocale())->setTitle($event->getTitle())->setVisible($event->getVisible() ? 1 : 0)->setVirtual($event->getVirtual() ? 1 : 0)->setTaxRule(TaxRuleQuery::create()->findOneByIsDefault(true))->create($event->getDefaultCategory(), $event->getBasePrice(), $event->getCurrencyId(), $event->getTaxRuleId(), $event->getBaseWeight());
// Set the product template, if one is defined in the category tree
$parentCatId = $event->getDefaultCategory();
while ($parentCatId > 0) {
if (null === ($cat = CategoryQuery::create()->findPk($parentCatId))) {
break;
}
if ($cat->getDefaultTemplateId()) {
$product->setTemplateId($cat->getDefaultTemplateId())->save();
break;
}
$parentCatId = $cat->getParent();
}
$event->setProduct($product);
}
示例15: delete
/**
* 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);
}
}