feature product loop + improve faker
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -296,14 +296,19 @@ class Product extends BaseLoop
|
||||
* - in promo if at least one the criteria matching PSE is in promo
|
||||
*/
|
||||
|
||||
if(count($isProductPriceLeftJoinList) == 0) {
|
||||
if(count($isPSELeftJoinList) == 0) {
|
||||
$isPSELeftJoinList[] = "global";
|
||||
$joiningTable = "global";
|
||||
$isPSELeftJoinList[] = $joiningTable;
|
||||
$search->joinProductSaleElements('global', Criteria::LEFT_JOIN);
|
||||
} if(count($isProductPriceLeftJoinList) == 0) {
|
||||
$isProductPriceLeftJoinList['global'] = 'global_price_data';
|
||||
} 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);
|
||||
|
||||
@@ -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; $j<rand(1, 5); $j++) {
|
||||
for($j=0; $j<rand(-2, 5); $j++) { //let a chance for no av
|
||||
$featureAv = new Thelia\Model\FeatureAv();
|
||||
$featureAv->setFeature($feature);
|
||||
$featureAv->setPosition($j);
|
||||
@@ -137,12 +153,103 @@ try {
|
||||
$subcategory = createCategory($faker, $category->getId(), $j, $categoryIdList);
|
||||
|
||||
for($k=0; $k<rand(0, 5); $k++) {
|
||||
createProduct($faker, $subcategory, $k, $currency, $productIdList);
|
||||
createProduct($faker, $subcategory, $k, $productIdList);
|
||||
}
|
||||
}
|
||||
|
||||
for($k=0; $k<rand(1, 5); $k++) {
|
||||
createProduct($faker, $category, $k, $currency, $productIdList);
|
||||
createProduct($faker, $category, $k, $productIdList);
|
||||
}
|
||||
}
|
||||
|
||||
//attribute_category and feature_category (all categories got all features/attributes)
|
||||
foreach($categoryIdList as $categoryId) {
|
||||
foreach($attributeList as $attributeId => $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; $i<rand(0, 4); $i++) {
|
||||
$accessory = new Thelia\Model\Accessory();
|
||||
do {
|
||||
$pick = array_rand($productIdList, 1);
|
||||
} while(in_array($pick, $alreadyPicked));
|
||||
|
||||
$alreadyPicked[] = $pick;
|
||||
|
||||
$accessory->setAccessory($productIdList[$pick])
|
||||
->setProductId($productId)
|
||||
->setPosition($i)
|
||||
->save();
|
||||
}
|
||||
|
||||
//associate PSE and stocks to products
|
||||
for($i=0; $i<rand(1,7); $i++) {
|
||||
$stock = new \Thelia\Model\ProductSaleElements();
|
||||
$stock->setProductId($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; $i<rand(-2,count($attributeList)); $i++) {
|
||||
$featureProduct = new Thelia\Model\AttributeCombination();
|
||||
do {
|
||||
$pick = array_rand($attributeList, 1);
|
||||
} while(in_array($pick, $alreadyPicked));
|
||||
|
||||
$alreadyPicked[] = $pick;
|
||||
|
||||
$featureProduct->setAttributeId($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; $i<rand(0, 4); $i++) {
|
||||
$accessory = new Thelia\Model\Accessory();
|
||||
$accessory->setAccessory($productIdList[array_rand($productIdList, 1)]);
|
||||
$accessory->setProductId($productId);
|
||||
$accessory->setPosition($i);
|
||||
|
||||
$accessory->save();
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<h3><a name="#REF">PRODUCT : #REF (#LOOP_COUNT / #LOOP_TOTAL)</a></h3>
|
||||
<h4>#TITLE</h4>
|
||||
<p>#DESCRIPTION</p>
|
||||
{*ifloop rel="acc"}
|
||||
{ifloop rel="acc"}
|
||||
<h5>Accessories</h5>
|
||||
<ul>
|
||||
{loop name="acc" type="accessory" product="#ID" order="accessory"}
|
||||
@@ -22,12 +22,18 @@
|
||||
{/ifloop}
|
||||
{elseloop rel="acc"}
|
||||
<h5>No accessory</h5>
|
||||
{/elseloop*}
|
||||
{/elseloop}
|
||||
{ifloop rel="ft"}
|
||||
<h5>Features</h5>
|
||||
<ul>
|
||||
{assign var=current_product value=#ID}
|
||||
{loop name="ft" type="feature" order="manual" product="#ID"}
|
||||
<li>#TITLE</li>
|
||||
<li>
|
||||
<strong>#TITLE</strong> :
|
||||
{loop name="ft_v" type="feature_value" product="{$current_product}" feature="#ID"}
|
||||
#TITLE / #PERSONAL_VALUE
|
||||
{/loop}
|
||||
</li>
|
||||
{/loop}
|
||||
</ul>
|
||||
{/ifloop}
|
||||
@@ -44,7 +50,7 @@
|
||||
<h3><a name="#REF">PRODUCT : #REF (#LOOP_COUNT / #LOOP_TOTAL)</a></h3>
|
||||
<h4>#TITLE</h4>
|
||||
<p>#DESCRIPTION</p>
|
||||
{*ifloop rel="acc"}
|
||||
{ifloop rel="acc"}
|
||||
<h5>Accessories</h5>
|
||||
<ul>
|
||||
{loop name="acc" type="accessory" product="#ID" order="accessory"}
|
||||
@@ -54,7 +60,7 @@
|
||||
{/ifloop}
|
||||
{elseloop rel="acc"}
|
||||
<h5>No accessory</h5>
|
||||
{/elseloop*}
|
||||
{/elseloop}
|
||||
{ifloop rel="ft"}
|
||||
<h5>Features</h5>
|
||||
<ul>
|
||||
@@ -113,13 +119,15 @@
|
||||
|
||||
<div style="border: solid 8px; margin: 0px; padding: 0px; width: 30%; float: left">
|
||||
|
||||
<h2>SANDBOX</h2>
|
||||
|
||||
{*loop name="product" type="product" order="promo,min_price" exclude_category="3" new="on" promo="off"}
|
||||
<h3>PRODUCT : #REF / #TITLE</h3>
|
||||
{/loop*}
|
||||
|
||||
{loop name="product" type="product" new="on" promo="off"}
|
||||
{*loop name="product" type="product" new="on" promo="off"}
|
||||
<h3>PRODUCT : #REF / #TITLE</h3>
|
||||
{/loop}
|
||||
{/loop*}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
|
||||
{/loop*}
|
||||
|
||||
{loop name="product" type="product" order="promo,min_price"}
|
||||
{*loop name="product" type="product" order="promo,min_price"}
|
||||
<h3>PRODUCT : #REF / #TITLE (#ID) / NEW : #NEW / PROMO : #PROMO / best price : #BEST_PRICE</h3>
|
||||
{/loop*}
|
||||
|
||||
{loop name="product" type="product"}
|
||||
<h3>PRODUCT : #REF / #TITLE</h3>
|
||||
{/loop}
|
||||
Reference in New Issue
Block a user