作者:marger
项目:theli
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);
}
作者:AnimalDesig
项目:thelia-piwik-analytic
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);
}
}
作者:roadster3
项目:thelia-modules-Vie
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);
}
作者:badela
项目:theli
/**
* @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;
}
作者:zorn-
项目:optimize-thelia-modul
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);
}
}
}
作者:badela
项目:theli
private function getCategoriesIdArray()
{
$categories = CategoryQuery::create()->select("id")->find()->toArray();
$ids = [];
foreach ($categories as $category) {
$ids[$category] = $category;
}
return $ids;
}
作者:alex6353
项目:theli
private function getCategoriesIdArray()
{
$categories = CategoryQuery::create()->find();
$ids = [];
foreach ($categories as $category) {
$ids[] = $category->getId();
}
return $ids;
}
作者:zorn-
项目:optimize-thelia-modul
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;
}
作者:AnimalDesig
项目:thelia-piwik-analytic
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());
}
作者:alex6353
项目:theli
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);
}
作者:Mertiozy
项目:GoogleShoppin
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;
}
作者:NandoKstroNe
项目:theli
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);
}
}
作者:hadesai
项目:theli
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'];
}
作者:savvage
项目:theli
/**
* 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);
}
作者:marger
项目:theli
/**
* 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);
}
}
作者:NandoKstroNe
项目:theli
/**
* @param array $argArray
* @depends testUpdate
*/
public function testRemoveTemplate($argArray)
{
$category = $argArray[0];
$template = $argArray[1];
$event = new TemplateDeleteEvent($template->getId());
$event->setDispatcher($this->getDispatcher());
$action = new \Thelia\Action\Template();
$action->delete($event);
$this->assertInstanceOf('Thelia\\Model\\Template', $event->getTemplate());
$theCat = CategoryQuery::create()->findPk($category->getId());
$this->assertNull($theCat->getDefaultTemplateId());
return $category;
}
作者:marger
项目:theli
/**
* @param UpdatePositionEvent $event
* @return null|\Symfony\Component\HttpFoundation\Response
*/
protected function performAdditionalUpdatePositionAction($event)
{
$category = CategoryQuery::create()->findPk($event->getObjectId());
$response = null;
if ($category != null) {
// Redirect to parent category list
$category_id = $category->getParent();
$response = $this->redirectToListTemplateWithId($category_id);
}
return $response;
}
作者:vigourouxjulie
项目:theli
/**
* Provides access to an attribute of the current category
*
* @param array $params
* @param \Smarty $smarty
* @return string the value of the requested attribute
*/
public function categoryDataAccess($params, &$smarty)
{
$categoryId = $this->getRequest()->get('category_id');
if ($categoryId === null) {
$productId = $this->getRequest()->get('product_id');
if ($productId !== null) {
if (null !== ($product = ProductQuery::create()->findPk($productId))) {
$categoryId = $product->getDefaultCategoryId();
}
}
}
if ($categoryId !== null) {
return $this->dataAccessWithI18n("Category", $params, CategoryQuery::create()->filterByPrimaryKey($categoryId));
}
return '';
}
作者:marger
项目:theli
protected function getCategory($locale = 'en_US')
{
$category = CategoryQuery::create()->joinCategoryI18n("category_i18n_join", Criteria::INNER_JOIN)->addJoinCondition('category_i18n_join', "locale = ?", $locale, null, \PDO::PARAM_STR)->findOne();
if (null === $category) {
$this->markTestSkipped(sprintf("You must have at least one category with an i18n that has the '%s' locale", $locale));
}
return $category;
}
作者:alex6353
项目:theli
public function categoryDataAccess($params, &$smarty)
{
$categoryId = $this->request->get('category_id');
if ($categoryId !== null) {
$search = CategoryQuery::create()->filterById($categoryId);
return $this->dataAccessWithI18n("Category", $params, $search);
}
}