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); } }
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); }
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); }
/** * @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; }
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); } } }
private function getCategoriesIdArray() { $categories = CategoryQuery::create()->select("id")->find()->toArray(); $ids = []; foreach ($categories as $category) { $ids[$category] = $category; } return $ids; }
private function getCategoriesIdArray() { $categories = CategoryQuery::create()->find(); $ids = []; foreach ($categories as $category) { $ids[] = $category->getId(); } return $ids; }
/** * Get the root category * @param int $categoryId * @return mixed */ public function getRoot($categoryId) { $category = CategoryQuery::create()->findPk($categoryId); if (0 !== $category->getParent()) { $parentCategory = CategoryQuery::create()->findPk($category->getParent()); if (null !== $parentCategory) { $categoryId = $this->getRoot($parentCategory->getId()); } } return $categoryId; }
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; }
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()); }
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); }
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; }
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); } }
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']; }
/** * 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); }
/** * 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); } }
/** * @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; }
/** * @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; }
/** * 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 ''; }
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; }
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); } }
public function buildModelCriteria() { Tlog::getInstance()->debug("-- Starting new product build criteria"); $currencyId = $this->getCurrency(); if (null !== $currencyId) { $currency = CurrencyQuery::create()->findOneById($currencyId); if (null === $currency) { throw new \InvalidArgumentException('Cannot found currency id: `' . $currency . '` in product_sale_elements loop'); } } else { $currency = $this->request->getSession()->getCurrency(); } $defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1); $defaultCurrencySuffix = '_default_currency'; $priceToCompareAsSQL = ''; $isPSELeftJoinList = []; $isProductPriceFirstLeftJoin = []; $search = ProductQuery::create(); $complex = $this->getComplex(); if (!$complex) { $search->innerJoinProductSaleElements('pse'); $search->addJoinCondition('pse', '`pse`.IS_DEFAULT=1'); $search->innerJoinProductSaleElements('pse_count'); $priceJoin = new Join(); $priceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'pse', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'price'); $priceJoin->setJoinType(Criteria::LEFT_JOIN); $search->addJoinObject($priceJoin, 'price_join')->addJoinCondition('price_join', '`price`.`currency_id` = ?', $currency->getId(), null, \PDO::PARAM_INT); if ($defaultCurrency->getId() != $currency->getId()) { $priceJoinDefaultCurrency = new Join(); $priceJoinDefaultCurrency->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'pse', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'price' . $defaultCurrencySuffix); $priceJoinDefaultCurrency->setJoinType(Criteria::LEFT_JOIN); $search->addJoinObject($priceJoinDefaultCurrency, 'price_join' . $defaultCurrencySuffix)->addJoinCondition('price_join' . $defaultCurrencySuffix, '`price' . $defaultCurrencySuffix . '`.`currency_id` = ?', $defaultCurrency->getId(), null, \PDO::PARAM_INT); /** * rate value is checked as a float in overloaded getRate method. */ $priceToCompareAsSQL = 'CASE WHEN ISNULL(`price`.PRICE) OR `price`.FROM_DEFAULT_CURRENCY = 1 THEN CASE WHEN `pse`.PROMO=1 THEN `price' . $defaultCurrencySuffix . '`.PROMO_PRICE ELSE `price' . $defaultCurrencySuffix . '`.PRICE END * ' . $currency->getRate() . ' ELSE CASE WHEN `pse`.PROMO=1 THEN `price`.PROMO_PRICE ELSE `price`.PRICE END END'; $search->withColumn('ROUND(' . $priceToCompareAsSQL . ', 2)', 'real_price'); $search->withColumn('CASE WHEN ISNULL(`price`.PRICE) OR `price`.FROM_DEFAULT_CURRENCY = 1 THEN `price' . $defaultCurrencySuffix . '`.PRICE * ' . $currency->getRate() . ' ELSE `price`.PRICE END', 'price'); $search->withColumn('CASE WHEN ISNULL(`price`.PRICE) OR `price`.FROM_DEFAULT_CURRENCY = 1 THEN `price' . $defaultCurrencySuffix . '`.PROMO_PRICE * ' . $currency->getRate() . ' ELSE `price`.PROMO_PRICE END', 'promo_price'); } else { $priceToCompareAsSQL = 'CASE WHEN `pse`.PROMO=1 THEN `price`.PROMO_PRICE ELSE `price`.PRICE END'; $search->withColumn('ROUND(' . $priceToCompareAsSQL . ', 2)', 'real_price'); $search->withColumn('`price`.PRICE', 'price'); $search->withColumn('`price`.PROMO_PRICE', 'promo_price'); } } /* manage translations */ $this->configureI18nProcessing($search, ['TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION', 'META_KEYWORDS']); $id = $this->getId(); if (!is_null($id)) { $search->filterById($id, Criteria::IN); } $ref = $this->getRef(); if (!is_null($ref)) { $search->filterByRef($ref, Criteria::IN); } $title = $this->getTitle(); if (!is_null($title)) { $search->where("CASE WHEN NOT ISNULL(`requested_locale_i18n`.ID) THEN `requested_locale_i18n`.`TITLE` ELSE `default_locale_i18n`.`TITLE` END " . Criteria::LIKE . " ?", "%" . $title . "%", \PDO::PARAM_STR); } $manualOrderAllowed = false; if (null !== ($categoryDefault = $this->getCategoryDefault())) { // Select the products which have $categoryDefault as the default category. $search->useProductCategoryQuery('DefaultCategorySelect')->filterByDefaultCategory(true)->filterByCategoryId($categoryDefault, Criteria::IN)->endUse(); // We can only sort by position if we have a single category ID $manualOrderAllowed = 1 == count($categoryDefault); } if (null !== ($categoryIdList = $this->getCategory())) { // Select all products which have one of the required categories as the default one, or an associated one $depth = $this->getDepth(); $allCategoryIDs = CategoryQuery::getCategoryTreeIds($categoryIdList, $depth); $search->useProductCategoryQuery('CategorySelect')->filterByCategoryId($allCategoryIDs, Criteria::IN)->endUse(); // We can only sort by position if we have a single category ID, with a depth of 1 $manualOrderAllowed = 1 == $depth && 1 == count($categoryIdList); } $current = $this->getCurrent(); if ($current === true) { $search->filterById($this->request->get("product_id"), Criteria::EQUAL); } elseif ($current === false) { $search->filterById($this->request->get("product_id"), Criteria::NOT_IN); } $brand_id = $this->getBrand(); if ($brand_id !== null) { $search->filterByBrandId($brand_id, Criteria::IN); } $sale_id = $this->getSale(); if ($sale_id !== null) { $search->useSaleProductQuery("SaleProductSelect")->filterBySaleId($sale_id)->groupByProductId()->endUse(); } $current_category = $this->getCurrent_category(); if ($current_category === true) { $search->filterByCategory(CategoryQuery::create()->filterByProduct(ProductCategoryQuery::create()->findPk($this->request->get("product_id")), Criteria::IN)->find(), Criteria::IN); } elseif ($current_category === false) { $search->filterByCategory(CategoryQuery::create()->filterByProduct(ProductCategoryQuery::create()->findPk($this->request->get("product_id")), Criteria::IN)->find(), Criteria::NOT_IN); } $visible = $this->getVisible(); if ($visible !== Type\BooleanOrBothType::ANY) { $search->filterByVisible($visible ? 1 : 0); } $virtual = $this->getVirtual(); if ($virtual !== Type\BooleanOrBothType::ANY) { $search->filterByVirtual($virtual ? 1 : 0); } $exclude = $this->getExclude(); if (!is_null($exclude)) { $search->filterById($exclude, Criteria::NOT_IN); } $exclude_category = $this->getExclude_category(); if (!is_null($exclude_category)) { $search->useProductCategoryQuery('ExcludeCategorySelect')->filterByCategoryId($exclude_category, Criteria::NOT_IN)->endUse(); } $new = $this->getNew(); $promo = $this->getPromo(); $min_stock = $this->getMin_stock(); $min_weight = $this->getMin_weight(); $max_weight = $this->getMax_weight(); $min_price = $this->getMin_price(); $max_price = $this->getMax_price(); if ($complex) { if ($new === true) { $isPSELeftJoinList[] = 'is_new'; $search->joinProductSaleElements('is_new', Criteria::LEFT_JOIN)->where('`is_new`.NEWNESS' . Criteria::EQUAL . '1')->where('NOT ISNULL(`is_new`.ID)'); } elseif ($new === false) { $isPSELeftJoinList[] = 'is_new'; $search->joinProductSaleElements('is_new', Criteria::LEFT_JOIN)->where('`is_new`.NEWNESS' . Criteria::EQUAL . '0')->where('NOT ISNULL(`is_new`.ID)'); } if ($promo === true) { $isPSELeftJoinList[] = 'is_promo'; $search->joinProductSaleElements('is_promo', Criteria::LEFT_JOIN)->where('`is_promo`.PROMO' . Criteria::EQUAL . '1')->where('NOT ISNULL(`is_promo`.ID)'); } elseif ($promo === false) { $isPSELeftJoinList[] = 'is_promo'; $search->joinProductSaleElements('is_promo', Criteria::LEFT_JOIN)->where('`is_promo`.PROMO' . Criteria::EQUAL . '0')->where('NOT ISNULL(`is_promo`.ID)'); } if (null != $min_stock) { $isPSELeftJoinList[] = 'is_min_stock'; $search->joinProductSaleElements('is_min_stock', Criteria::LEFT_JOIN)->where('`is_min_stock`.QUANTITY' . Criteria::GREATER_THAN . '?', $min_stock, \PDO::PARAM_INT)->where('NOT ISNULL(`is_min_stock`.ID)'); } if (null != $min_weight) { $isPSELeftJoinList[] = 'is_min_weight'; $search->joinProductSaleElements('is_min_weight', Criteria::LEFT_JOIN)->where('`is_min_weight`.WEIGHT' . Criteria::GREATER_THAN . '?', $min_weight, \PDO::PARAM_STR)->where('NOT ISNULL(`is_min_weight`.ID)'); } if (null != $max_weight) { $isPSELeftJoinList[] = 'is_max_weight'; $search->joinProductSaleElements('is_max_weight', Criteria::LEFT_JOIN)->where('`is_max_weight`.WEIGHT' . Criteria::LESS_THAN . '?', $max_weight, \PDO::PARAM_STR)->where('NOT ISNULL(`is_max_weight`.ID)'); } $attributeNonStrictMatch = $this->getAttribute_non_strict_match(); if ($attributeNonStrictMatch != '*') { if ($attributeNonStrictMatch == 'none') { $actuallyUsedAttributeNonStrictMatchList = $isPSELeftJoinList; } else { $actuallyUsedAttributeNonStrictMatchList = array_values(array_intersect($isPSELeftJoinList, $attributeNonStrictMatch)); } foreach ($actuallyUsedAttributeNonStrictMatchList as $key => $actuallyUsedAttributeNonStrictMatch) { if ($key == 0) { continue; } $search->where('`' . $actuallyUsedAttributeNonStrictMatch . '`.ID=' . '`' . $actuallyUsedAttributeNonStrictMatchList[$key - 1] . '`.ID'); } } if (null !== $min_price) { if (false === ConfigQuery::useTaxFreeAmounts()) { // @todo } $isPSELeftJoinList[] = 'is_min_price'; $isProductPriceFirstLeftJoin = ['is_min_price', 'min_price_data']; $minPriceJoin = new Join(); $minPriceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'is_min_price', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'min_price_data'); $minPriceJoin->setJoinType(Criteria::LEFT_JOIN); $search->joinProductSaleElements('is_min_price', Criteria::LEFT_JOIN)->addJoinObject($minPriceJoin, 'is_min_price_join')->addJoinCondition('is_min_price_join', '`min_price_data`.`currency_id` = ?', $currency->getId(), null, \PDO::PARAM_INT); if ($defaultCurrency->getId() != $currency->getId()) { $minPriceJoinDefaultCurrency = new Join(); $minPriceJoinDefaultCurrency->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'is_min_price', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'min_price_data' . $defaultCurrencySuffix); $minPriceJoinDefaultCurrency->setJoinType(Criteria::LEFT_JOIN); $search->addJoinObject($minPriceJoinDefaultCurrency, 'is_min_price_join' . $defaultCurrencySuffix)->addJoinCondition('is_min_price_join' . $defaultCurrencySuffix, '`min_price_data' . $defaultCurrencySuffix . '`.`currency_id` = ?', $defaultCurrency->getId(), null, \PDO::PARAM_INT); /** * In propel we trust : $currency->getRate() always returns a float. * Or maybe not : rate value is checked as a float in overloaded getRate method. */ $MinPriceToCompareAsSQL = 'CASE WHEN ISNULL(CASE WHEN `is_min_price`.PROMO=1 THEN `min_price_data`.PROMO_PRICE ELSE `min_price_data`.PRICE END) OR `min_price_data`.FROM_DEFAULT_CURRENCY = 1 THEN CASE WHEN `is_min_price`.PROMO=1 THEN `min_price_data' . $defaultCurrencySuffix . '`.PROMO_PRICE ELSE `min_price_data' . $defaultCurrencySuffix . '`.PRICE END * ' . $currency->getRate() . ' ELSE CASE WHEN `is_min_price`.PROMO=1 THEN `min_price_data`.PROMO_PRICE ELSE `min_price_data`.PRICE END END'; } else { $MinPriceToCompareAsSQL = 'CASE WHEN `is_min_price`.PROMO=1 THEN `min_price_data`.PROMO_PRICE ELSE `min_price_data`.PRICE END'; } $search->where('ROUND(' . $MinPriceToCompareAsSQL . ', 2)>=?', $min_price, \PDO::PARAM_STR); } if (null !== $max_price) { $isPSELeftJoinList[] = 'is_max_price'; $isProductPriceFirstLeftJoin = ['is_max_price', 'max_price_data']; $maxPriceJoin = new Join(); $maxPriceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'is_max_price', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'max_price_data'); $maxPriceJoin->setJoinType(Criteria::LEFT_JOIN); $search->joinProductSaleElements('is_max_price', Criteria::LEFT_JOIN)->addJoinObject($maxPriceJoin, 'is_max_price_join')->addJoinCondition('is_max_price_join', '`max_price_data`.`currency_id` = ?', $currency->getId(), null, \PDO::PARAM_INT); if ($defaultCurrency->getId() != $currency->getId()) { $maxPriceJoinDefaultCurrency = new Join(); $maxPriceJoinDefaultCurrency->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'is_max_price', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'max_price_data' . $defaultCurrencySuffix); $maxPriceJoinDefaultCurrency->setJoinType(Criteria::LEFT_JOIN); $search->addJoinObject($maxPriceJoinDefaultCurrency, 'is_max_price_join' . $defaultCurrencySuffix)->addJoinCondition('is_max_price_join' . $defaultCurrencySuffix, '`max_price_data' . $defaultCurrencySuffix . '`.`currency_id` = ?', $defaultCurrency->getId(), null, \PDO::PARAM_INT); /** * In propel we trust : $currency->getRate() always returns a float. * Or maybe not : rate value is checked as a float in overloaded getRate method. */ $MaxPriceToCompareAsSQL = 'CASE WHEN ISNULL(CASE WHEN `is_max_price`.PROMO=1 THEN `max_price_data`.PROMO_PRICE ELSE `max_price_data`.PRICE END) OR `min_price_data`.FROM_DEFAULT_CURRENCY = 1 THEN CASE WHEN `is_max_price`.PROMO=1 THEN `max_price_data' . $defaultCurrencySuffix . '`.PROMO_PRICE ELSE `max_price_data' . $defaultCurrencySuffix . '`.PRICE END * ' . $currency->getRate() . ' ELSE CASE WHEN `is_max_price`.PROMO=1 THEN `max_price_data`.PROMO_PRICE ELSE `max_price_data`.PRICE END END'; } else { $MaxPriceToCompareAsSQL = 'CASE WHEN `is_max_price`.PROMO=1 THEN `max_price_data`.PROMO_PRICE ELSE `max_price_data`.PRICE END'; } $search->where('ROUND(' . $MaxPriceToCompareAsSQL . ', 2)<=?', $max_price, \PDO::PARAM_STR); } /* * for ordering and outputs, the product will be : * - new if at least one the criteria matching PSE is new * - in promo if at least one the criteria matching PSE is in promo */ /* if we don't have any join yet, let's make a global one */ if (empty($isProductPriceFirstLeftJoin)) { if (count($isPSELeftJoinList) == 0) { $joiningTable = "global"; $isPSELeftJoinList[] = $joiningTable; $search->joinProductSaleElements('global', Criteria::LEFT_JOIN); } else { $joiningTable = $isPSELeftJoinList[0]; } $isProductPriceFirstLeftJoin = [$joiningTable, 'global_price_data']; $globalPriceJoin = new Join(); $globalPriceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', $joiningTable, ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'global_price_data'); $globalPriceJoin->setJoinType(Criteria::LEFT_JOIN); $search->addJoinObject($globalPriceJoin, 'global_price_join')->addJoinCondition('global_price_join', '`global_price_data`.`currency_id` = ?', $currency->getId(), null, \PDO::PARAM_INT); if ($defaultCurrency->getId() != $currency->getId()) { $globalPriceJoinDefaultCurrency = new Join(); $globalPriceJoinDefaultCurrency->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', $joiningTable, ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'global_price_data' . $defaultCurrencySuffix); $globalPriceJoinDefaultCurrency->setJoinType(Criteria::LEFT_JOIN); $search->addJoinObject($globalPriceJoinDefaultCurrency, 'global_price_join' . $defaultCurrencySuffix)->addJoinCondition('global_price_join' . $defaultCurrencySuffix, '`global_price_data' . $defaultCurrencySuffix . '`.`currency_id` = ?', $defaultCurrency->getId(), null, \PDO::PARAM_INT); } } /* * we need to test all promo field from our previous conditions. Indeed ie: * product P0, attributes color : red * P0red is in promo and is the only attribute combinaton availability. * so the product might be consider as in promo (in outputs and ordering) * We got the following loop to display in promo AND new product but we don't care it's the same attribute which is new and in promo : * {loop type="product" promo="1" new="1" attribute_non_strict_match="promo,new"} {/loop} * our request will so far returns 1 line * * is_promo.ID | is_promo.PROMO | is_promo.NEWNESS | is_new.ID | is_new.PROMO | is_new.NEWNESS * NULL NULL NULL red_id 1 0 * * So that we can say the product is in global promo only with is_promo.PROMO, we must acknowledge it with (is_promo.PROMO OR is_new.PROMO) */ $booleanMatchedPromoList = []; $booleanMatchedNewnessList = []; foreach ($isPSELeftJoinList as $isPSELeftJoin) { $booleanMatchedPromoList[] = '`' . $isPSELeftJoin . '`.PROMO'; $booleanMatchedNewnessList[] = '`' . $isPSELeftJoin . '`.NEWNESS'; } $search->withColumn('ROUND(MAX(' . implode(' OR ', $booleanMatchedPromoList) . '), 2)', 'main_product_is_promo'); $search->withColumn('ROUND(MAX(' . implode(' OR ', $booleanMatchedNewnessList) . '), 2)', 'main_product_is_new'); $booleanMatchedPrice = 'CASE WHEN `' . $isProductPriceFirstLeftJoin[0] . '`.PROMO=1 THEN `' . $isProductPriceFirstLeftJoin[1] . '`.PROMO_PRICE ELSE `' . $isProductPriceFirstLeftJoin[1] . '`.PRICE END'; $booleanMatchedPriceDefaultCurrency = 'CASE WHEN `' . $isProductPriceFirstLeftJoin[0] . '`.PROMO=1 THEN `' . $isProductPriceFirstLeftJoin[1] . $defaultCurrencySuffix . '`.PROMO_PRICE ELSE `' . $isProductPriceFirstLeftJoin[1] . $defaultCurrencySuffix . '`.PRICE END'; if ($defaultCurrency->getId() != $currency->getId()) { /** * In propel we trust : $currency->getRate() always returns a float. * Or maybe not : rate value is checked as a float in overloaded getRate method. */ $priceToCompareAsSQL = 'CASE WHEN ISNULL(' . $booleanMatchedPrice . ') THEN ' . $booleanMatchedPriceDefaultCurrency . ' * ' . $currency->getRate() . ' ELSE ' . $booleanMatchedPrice . ' END'; } else { $priceToCompareAsSQL = $booleanMatchedPrice; } $search->withColumn('ROUND(MAX(' . $priceToCompareAsSQL . '), 2)', 'real_highest_price'); $search->withColumn('ROUND(MIN(' . $priceToCompareAsSQL . '), 2)', 'real_lowest_price'); } else { if ($new === true) { $search->where('`pse`.NEWNESS' . Criteria::EQUAL . '1'); } elseif ($new === false) { $search->where('`pse`.NEWNESS' . Criteria::EQUAL . '0'); } if ($promo === true) { $search->where('`pse`.PROMO' . Criteria::EQUAL . '1'); } elseif ($promo === false) { $search->where('`pse`.PROMO' . Criteria::EQUAL . '0'); } if (null != $min_stock) { $search->where('`pse`.QUANTITY' . Criteria::GREATER_THAN . '?', $min_stock, \PDO::PARAM_INT); } if (null != $min_weight) { $search->where('`pse`.WEIGHT' . Criteria::GREATER_THAN . '?', $min_weight, \PDO::PARAM_STR); } if (null != $max_weight) { $search->where('`is_max_weight`.WEIGHT' . Criteria::LESS_THAN . '?', $max_weight, \PDO::PARAM_STR); } if (null !== $min_price) { if (false === ConfigQuery::useTaxFreeAmounts()) { // @todo } $search->where('ROUND(' . $priceToCompareAsSQL . ', 2)>=?', $min_price, \PDO::PARAM_STR); } if (null !== $max_price) { if (false === ConfigQuery::useTaxFreeAmounts()) { // @todo } $search->where('ROUND(' . $priceToCompareAsSQL . ', 2)<=?', $max_price, \PDO::PARAM_STR); } } // First join sale_product table... $search->leftJoinSaleProduct('SaleProductPriceDisplay'); // ... then the sale table... $salesJoin = new Join(); $salesJoin->addExplicitCondition('SaleProductPriceDisplay', 'SALE_ID', null, SaleTableMap::TABLE_NAME, 'ID', 'SalePriceDisplay'); $salesJoin->setJoinType(Criteria::LEFT_JOIN); $search->addJoinObject($salesJoin, 'SalePriceDisplay')->addJoinCondition('SalePriceDisplay', '`SalePriceDisplay`.`active` = 1'); // ... to get the DISPLAY_INITIAL_PRICE column ! $search->withColumn('`SalePriceDisplay`.DISPLAY_INITIAL_PRICE', 'display_initial_price'); $feature_availability = $this->getFeature_availability(); $this->manageFeatureAv($search, $feature_availability); $feature_values = $this->getFeature_values(); $this->manageFeatureValue($search, $feature_values); $search->groupBy(ProductTableMap::ID); if (!$complex) { $search->withColumn('`pse`.ID', 'pse_id'); $search->withColumn('`pse`.NEWNESS', 'is_new'); $search->withColumn('`pse`.PROMO', 'is_promo'); $search->withColumn('`pse`.QUANTITY', 'quantity'); $search->withColumn('`pse`.WEIGHT', 'weight'); $search->withColumn('`pse`.EAN_CODE', 'ean_code'); $search->withColumn('COUNT(`pse_count`.ID)', 'pse_count'); } $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 "min_price": if ($complex) { $search->addAscendingOrderByColumn('real_lowest_price', Criteria::ASC); } else { $search->addAscendingOrderByColumn('real_price'); } break; case "max_price": if ($complex) { $search->addDescendingOrderByColumn('real_lowest_price'); } else { $search->addDescendingOrderByColumn('real_price'); } break; case "manual": if (!$manualOrderAllowed) { throw new \InvalidArgumentException('Manual order require a *single* category ID or category_default ID, and a depth <= 1'); } $search->orderByPosition(Criteria::ASC); break; case "manual_reverse": if (!$manualOrderAllowed) { throw new \InvalidArgumentException('Manual reverse order require a *single* category ID or category_default ID, and a depth <= 1'); } $search->orderByPosition(Criteria::DESC); break; case "ref": $search->orderByRef(Criteria::ASC); break; case "ref_reverse": $search->orderByRef(Criteria::DESC); break; case "promo": if ($complex) { $search->addDescendingOrderByColumn('main_product_is_promo'); } else { $search->addDescendingOrderByColumn('is_promo'); } break; case "new": if ($complex) { $search->addDescendingOrderByColumn('main_product_is_new'); } else { $search->addDescendingOrderByColumn('is_new'); } break; case "created": $search->addAscendingOrderByColumn('created_at'); break; case "created_reverse": $search->addDescendingOrderByColumn('created_at'); break; case "updated": $search->addAscendingOrderByColumn('updated_at'); break; case "updated_reverse": $search->addDescendingOrderByColumn('updated_at'); break; case "given_id": if (null === $id) { throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument'); } foreach ($id as $singleId) { $givenIdMatched = 'given_id_matched_' . $singleId; $search->withColumn(ProductTableMap::ID . "='{$singleId}'", $givenIdMatched); $search->orderBy($givenIdMatched, Criteria::DESC); } break; case "random": $search->clearOrderByColumns(); $search->addAscendingOrderByColumn('RAND()'); break 2; } } return $search; }
public function parseResults(LoopResult $loopResult) { /** @var CategoryModel $category */ foreach ($loopResult->getResultDataCollection() as $category) { /* * no cause pagination lost : * if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue; */ $loopResultRow = new LoopResultRow($category); $loopResultRow->set("ID", $category->getId())->set("IS_TRANSLATED", $category->getVirtualColumn('IS_TRANSLATED'))->set("LOCALE", $this->locale)->set("TITLE", $category->getVirtualColumn('i18n_TITLE'))->set("CHAPO", $category->getVirtualColumn('i18n_CHAPO'))->set("DESCRIPTION", $category->getVirtualColumn('i18n_DESCRIPTION'))->set("POSTSCRIPTUM", $category->getVirtualColumn('i18n_POSTSCRIPTUM'))->set("PARENT", $category->getParent())->set("ROOT", $category->getRoot($category->getId()))->set("URL", $this->getReturnUrl() ? $category->getUrl($this->locale) : null)->set("META_TITLE", $category->getVirtualColumn('i18n_META_TITLE'))->set("META_DESCRIPTION", $category->getVirtualColumn('i18n_META_DESCRIPTION'))->set("META_KEYWORDS", $category->getVirtualColumn('i18n_META_KEYWORDS'))->set("VISIBLE", $category->getVisible() ? "1" : "0")->set("POSITION", $category->getPosition())->set("TEMPLATE", $category->getDefaultTemplateId()); if ($this->getNeedCountChild()) { $loopResultRow->set("CHILD_COUNT", $category->countChild()); } if ($this->getNeedProductCount()) { $loopResultRow->set("PRODUCT_COUNT", $category->countAllProducts()); } $isBackendContext = $this->getBackendContext(); if ($this->getWithPrevNextInfo()) { // Find previous and next category $previousQuery = CategoryQuery::create()->filterByParent($category->getParent())->filterByPosition($category->getPosition(), Criteria::LESS_THAN); if (!$isBackendContext) { $previousQuery->filterByVisible(true); } $previous = $previousQuery->orderByPosition(Criteria::DESC)->findOne(); $nextQuery = CategoryQuery::create()->filterByParent($category->getParent())->filterByPosition($category->getPosition(), Criteria::GREATER_THAN); if (!$isBackendContext) { $nextQuery->filterByVisible(true); } $next = $nextQuery->orderByPosition(Criteria::ASC)->findOne(); $loopResultRow->set("HAS_PREVIOUS", $previous != null ? 1 : 0)->set("HAS_NEXT", $next != null ? 1 : 0)->set("PREVIOUS", $previous != null ? $previous->getId() : -1)->set("NEXT", $next != null ? $next->getId() : -1); } $this->addOutputFields($loopResultRow, $category); $loopResult->addRow($loopResultRow); } return $loopResult; }
/** * @depends testRemoveContent */ public function testAddCategory(ProductModel $product) { $categories = $product->getProductCategories(); $this->assertEquals(1, count($categories)); $defaultCategory = $categories->getFirst(); $category = CategoryQuery::create()->filterById($defaultCategory->getCategoryId(), Criteria::NOT_IN)->addAscendingOrderByColumn('RAND()')->findOne(); $event = new ProductAddCategoryEvent($product, $category->getId()); $event->setDispatcher($this->getDispatcher()); $action = new Product(); $action->addCategory($event); $product->clearProductCategories(); $newCategories = $product->getProductCategories(); $this->assertEquals(2, count($newCategories)); return array('product' => $product, 'category' => $category); }
/** * Changes position, selecting absolute ou relative change. * * @param CategoryChangePositionEvent $event */ public function updatePosition(UpdatePositionEvent $event) { $this->genericUpdatePosition(CategoryQuery::create(), $event); }
$stmt = $con->prepare("SET foreign_key_checks = 0"); $stmt->execute(); echo "Clearing tables\n"; Model\ProductAssociatedContentQuery::create()->deleteAll(); Model\CategoryAssociatedContentQuery::create()->deleteAll(); Model\FeatureProductQuery::create()->deleteAll(); Model\AttributeCombinationQuery::create()->deleteAll(); Model\FeatureQuery::create()->deleteAll(); Model\FeatureI18nQuery::create()->deleteAll(); Model\FeatureAvQuery::create()->deleteAll(); Model\FeatureAvI18nQuery::create()->deleteAll(); Model\AttributeQuery::create()->deleteAll(); Model\AttributeI18nQuery::create()->deleteAll(); Model\AttributeAvQuery::create()->deleteAll(); Model\AttributeAvI18nQuery::create()->deleteAll(); Model\CategoryQuery::create()->deleteAll(); Model\CategoryI18nQuery::create()->deleteAll(); Model\ProductQuery::create()->deleteAll(); Model\ProductI18nQuery::create()->deleteAll(); Model\CustomerQuery::create()->deleteAll(); Model\AdminQuery::create()->deleteAll(); Model\FolderQuery::create()->deleteAll(); Model\FolderI18nQuery::create()->deleteAll(); Model\ContentQuery::create()->deleteAll(); Model\ContentI18nQuery::create()->deleteAll(); Model\AccessoryQuery::create()->deleteAll(); Model\ProductSaleElementsQuery::create()->deleteAll(); Model\ProductPriceQuery::create()->deleteAll(); Model\BrandQuery::create()->deleteAll(); Model\BrandI18nQuery::create()->deleteAll(); Model\ProductImageQuery::create()->deleteAll();
/** * Get the associated ChildCategory object * * @param ConnectionInterface $con Optional Connection object. * @return ChildCategory The associated ChildCategory object. * @throws PropelException */ public function getCategory(ConnectionInterface $con = null) { if ($this->aCategory === null && $this->id !== null) { $this->aCategory = ChildCategoryQuery::create()->findPk($this->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->aCategory->addCategoryVersions($this); */ } return $this->aCategory; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see Category::setDeleted() * @see Category::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(CategoryTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildCategoryQuery::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 postImport() { // Fix parent IDs for each categories, which are still T1 parent IDs $obj_list = CategoryQuery::create()->orderById()->find(); foreach ($obj_list as $obj) { $t1_parent = $obj->getParent() - 1000000; if ($t1_parent > 0) { $obj->setParent($this->cat_corresp->getT2($t1_parent))->save(); } } }
public function getAvailableAccessoriesAction($productId, $categoryId) { $result = array(); $categories = CategoryQuery::create()->filterById($categoryId)->find(); if ($categories !== null) { $list = ProductQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->filterByCategory($categories, Criteria::IN)->filterById(AccessoryQuery::create()->select('accessory')->findByProductId($productId), Criteria::NOT_IN)->find(); if ($list !== null) { /** @var Product $item */ foreach ($list as $item) { $result[] = array('id' => $item->getId(), 'title' => $item->getTitle()); } } } return $this->jsonResponse(json_encode($result)); }