From 6a14bef3de668375aa8834e97065d38b3523816a Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 20 Aug 2013 17:59:22 +0200 Subject: [PATCH] feature product loop + improve faker --- .../Core/Template/Loop/FeatureValue.php | 31 ++-- .../lib/Thelia/Core/Template/Loop/Product.php | 17 ++- install/faker.php | 140 ++++++++++++++---- templates/default/category.html | 22 ++- templates/default/debug.html | 6 +- 5 files changed, 154 insertions(+), 62 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php index 403baf37a..2d5689462 100755 --- a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php +++ b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php @@ -35,6 +35,7 @@ use Thelia\Log\Tlog; use Thelia\Model\Base\FeatureProductQuery; use Thelia\Model\ConfigQuery; +use Thelia\Model\FeatureAvQuery; use Thelia\Type\TypeCollection; use Thelia\Type; @@ -108,31 +109,20 @@ class FeatureValue extends BaseLoop foreach($orders as $order) { switch ($order) { case "alpha": - $search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE); + //$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE); break; case "alpha_reverse": - $search->addDescendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE); + //$search->addDescendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE); break; case "manual": - $search->orderByPosition(Criteria::ASC); + //$search->orderByPosition(Criteria::ASC); break; case "manual_reverse": - $search->orderByPosition(Criteria::DESC); + //$search->orderByPosition(Criteria::DESC); break; } } - /** - * Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation. - * - * @todo : verify here if we want results for row without translations. - */ - - /*$search->joinWithI18n( - $this->request->getSession()->getLocale(), - (ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN - );*/ - $featureValues = $this->search($search, $pagination); $loopResult = new LoopResult(); @@ -140,10 +130,13 @@ class FeatureValue extends BaseLoop foreach ($featureValues as $featureValue) { $loopResultRow = new LoopResultRow(); $loopResultRow->set("ID", $featureValue->getId()); - /*$loopResultRow->set("TITLE",$featureValue->getTitle()); - $loopResultRow->set("CHAPO", $featureValue->getChapo()); - $loopResultRow->set("DESCRIPTION", $featureValue->getDescription()); - $loopResultRow->set("POSTSCRIPTUM", $featureValue->getPostscriptum());*/ + + $loopResultRow->set("PERSONAL_VALUE", $featureValue->getByDefault()); + + $loopResultRow->set("TITLE", $featureValue->getFeatureAv()->getTitle()); + $loopResultRow->set("CHAPO", $featureValue->getFeatureAv()->getChapo()); + $loopResultRow->set("DESCRIPTION", $featureValue->getFeatureAv()->getDescription()); + $loopResultRow->set("POSTSCRIPTUM", $featureValue->getFeatureAv()->getPostscriptum()); $loopResult->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 76d628b56..31a488f7e 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -296,14 +296,19 @@ class Product extends BaseLoop * - in promo if at least one the criteria matching PSE is in promo */ - if(count($isPSELeftJoinList) == 0) { - $isPSELeftJoinList[] = "global"; - $search->joinProductSaleElements('global', Criteria::LEFT_JOIN); - } if(count($isProductPriceLeftJoinList) == 0) { - $isProductPriceLeftJoinList['global'] = 'global_price_data'; + if(count($isProductPriceLeftJoinList) == 0) { + if(count($isPSELeftJoinList) == 0) { + $joiningTable = "global"; + $isPSELeftJoinList[] = $joiningTable; + $search->joinProductSaleElements('global', Criteria::LEFT_JOIN); + } else { + $joiningTable = $isPSELeftJoinList[0]; + } + + $isProductPriceLeftJoinList[$joiningTable] = 'global_price_data'; $minPriceJoin = new Join(); - $minPriceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'global', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'global_price_data'); + $minPriceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', $joiningTable, ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'global_price_data'); $minPriceJoin->setJoinType(Criteria::LEFT_JOIN); $search->addJoinObject($minPriceJoin); diff --git a/install/faker.php b/install/faker.php index d3d073994..9da307540 100755 --- a/install/faker.php +++ b/install/faker.php @@ -12,6 +12,22 @@ $currency = \Thelia\Model\CurrencyQuery::create()->filterByCode('EUR')->findOne( try { + $attributeCategory = Thelia\Model\AttributeCategoryQuery::create() + ->find(); + $attributeCategory->delete(); + + $featureCategory = Thelia\Model\FeatureCategoryQuery::create() + ->find(); + $featureCategory->delete(); + + $featureProduct = Thelia\Model\FeatureProductQuery::create() + ->find(); + $featureProduct->delete(); + + $attributeCombination = Thelia\Model\AttributeCombinationQuery::create() + ->find(); + $attributeCombination->delete(); + $feature = Thelia\Model\FeatureQuery::create() ->find(); $feature->delete(); @@ -91,7 +107,7 @@ try { $featureId = $feature->getId(); $featureList[$featureId] = array(); - for($j=0; $jsetFeature($feature); $featureAv->setPosition($j); @@ -137,12 +153,103 @@ try { $subcategory = createCategory($faker, $category->getId(), $j, $categoryIdList); for($k=0; $k $attributeAvId) { + $attributeCategory = new Thelia\Model\AttributeCategory(); + $attributeCategory->setCategoryId($categoryId) + ->setAttributeId($attributeId) + ->save(); + } + foreach($featureList as $featureId => $featureAvId) { + $featureCategory = new Thelia\Model\FeatureCategory(); + $featureCategory->setCategoryId($categoryId) + ->setFeatureId($featureId) + ->save(); + } + } + + foreach($productIdList as $productId) { + //add random accessories - or not + $alreadyPicked = array(); + for($i=1; $isetAccessory($productIdList[$pick]) + ->setProductId($productId) + ->setPosition($i) + ->save(); + } + + //associate PSE and stocks to products + for($i=0; $isetProductId($productId); + $stock->setQuantity($faker->randomNumber(1,50)); + $stock->setPromo($faker->randomNumber(0,1)); + $stock->setNewness($faker->randomNumber(0,1)); + $stock->setWeight($faker->randomFloat(2, 100,10000)); + $stock->save(); + + $productPrice = new \Thelia\Model\ProductPrice(); + $productPrice->setProductSaleElements($stock); + $productPrice->setCurrency($currency); + $productPrice->setPrice($faker->randomFloat(2, 20, 250)); + $productPrice->setPromoPrice($faker->randomFloat(2, 20, 250)); + $productPrice->save(); + + //associate attributes - or not - to PSE + + $alreadyPicked = array(); + for($i=0; $isetAttributeId($pick) + ->setAttributeAvId($attributeList[$pick][array_rand($attributeList[$pick], 1)]) + ->setProductSaleElements($stock) + ->save(); + } + } + + + foreach($attributeList as $attributeId => $attributeAvId) { + + } + + //associate features to products + foreach($featureList as $featureId => $featureAvId) { + $featureProduct = new Thelia\Model\FeatureProduct(); + $featureProduct->setProductId($productId) + ->setFeatureId($featureId); + + if(count($featureAvId) > 0) { //got some av + $featureProduct->setFeatureAvId( + $featureAvId[array_rand($featureAvId, 1)] + ); + } else { //no av + $featureProduct->setByDefault($faker->text(10)); + } + + $featureProduct->save(); } } @@ -186,7 +293,7 @@ try { $con->rollBack(); } -function createProduct($faker, $category, $position, $currency, &$productIdList) +function createProduct($faker, $category, $position, &$productIdList) { $product = new Thelia\Model\Product(); $product->setRef($category->getId() . '_' . $position . '_' . $faker->randomNumber(8)); @@ -200,31 +307,6 @@ function createProduct($faker, $category, $position, $currency, &$productIdList) $productId = $product->getId(); $productIdList[] = $productId; - $stock = new \Thelia\Model\ProductSaleElements(); - $stock->setProduct($product); - $stock->setQuantity($faker->randomNumber(1,50)); - $stock->setPromo($faker->randomNumber(0,1)); - $stock->setNewness($faker->randomNumber(0,1)); - $stock->setWeight($faker->randomFloat(2, 100,10000)); - $stock->save(); - - $productPrice = new \Thelia\Model\ProductPrice(); - $productPrice->setProductSaleElements($stock); - $productPrice->setCurrency($currency); - $productPrice->setPrice($faker->randomFloat(2, 20, 250)); - $productPrice->setPromoPrice($faker->randomFloat(2, 20, 250)); - $productPrice->save(); - - //add random accessories - or not - for($i=1; $isetAccessory($productIdList[array_rand($productIdList, 1)]); - $accessory->setProductId($productId); - $accessory->setPosition($i); - - $accessory->save(); - } - return $product; } diff --git a/templates/default/category.html b/templates/default/category.html index 6a671f78a..fd4651a93 100755 --- a/templates/default/category.html +++ b/templates/default/category.html @@ -12,7 +12,7 @@

PRODUCT : #REF (#LOOP_COUNT / #LOOP_TOTAL)

#TITLE

#DESCRIPTION

- {*ifloop rel="acc"} + {ifloop rel="acc"}
Accessories
    {loop name="acc" type="accessory" product="#ID" order="accessory"} @@ -22,12 +22,18 @@ {/ifloop} {elseloop rel="acc"}
    No accessory
    - {/elseloop*} + {/elseloop} {ifloop rel="ft"}
    Features
      + {assign var=current_product value=#ID} {loop name="ft" type="feature" order="manual" product="#ID"} -
    • #TITLE
    • +
    • + #TITLE : + {loop name="ft_v" type="feature_value" product="{$current_product}" feature="#ID"} + #TITLE / #PERSONAL_VALUE + {/loop} +
    • {/loop}
    {/ifloop} @@ -44,7 +50,7 @@

    PRODUCT : #REF (#LOOP_COUNT / #LOOP_TOTAL)

    #TITLE

    #DESCRIPTION

    - {*ifloop rel="acc"} + {ifloop rel="acc"}
    Accessories
      {loop name="acc" type="accessory" product="#ID" order="accessory"} @@ -54,7 +60,7 @@ {/ifloop} {elseloop rel="acc"}
      No accessory
      - {/elseloop*} + {/elseloop} {ifloop rel="ft"}
      Features
        @@ -113,13 +119,15 @@
        +

        SANDBOX

        + {*loop name="product" type="product" order="promo,min_price" exclude_category="3" new="on" promo="off"}

        PRODUCT : #REF / #TITLE

        {/loop*} -{loop name="product" type="product" new="on" promo="off"} +{*loop name="product" type="product" new="on" promo="off"}

        PRODUCT : #REF / #TITLE

        -{/loop} +{/loop*} diff --git a/templates/default/debug.html b/templates/default/debug.html index 72bbc332b..251a9b891 100644 --- a/templates/default/debug.html +++ b/templates/default/debug.html @@ -14,6 +14,10 @@

        PRODUCT : #REF / #TITLE (#ID)

        {/loop*} -{loop name="product" type="product" order="promo,min_price"} +{*loop name="product" type="product" order="promo,min_price"}

        PRODUCT : #REF / #TITLE (#ID) / NEW : #NEW / PROMO : #PROMO / best price : #BEST_PRICE

        +{/loop*} + +{loop name="product" type="product"} +

        PRODUCT : #REF / #TITLE

        {/loop} \ No newline at end of file