Recettes : BO, rajout de l'ajax

This commit is contained in:
2021-05-07 14:02:09 +02:00
parent 16bfe33efd
commit 5e1fe56d56
36 changed files with 1331 additions and 58 deletions

View File

@@ -2,6 +2,8 @@
namespace Recettes\Loop;
use mysql_xdevapi\Exception;
use Propel\Runtime\Exception\PropelException;
use Recettes\Model\RecipeProductsQuery;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
@@ -31,29 +33,35 @@ class ProductsLoop extends BaseLoop implements PropelSearchLoopInterface
*/
public function parseResults(LoopResult $loopResult)
{
$someProductsNotInStock = false;
foreach ($loopResult->getResultDataCollection() as $product) {
$pse = ProductSaleElementsQuery::create()->findOneById($product->getPseId());
$productId = $pse->getProductId();
$productLabel = ProductI18nQuery::create()->findOneById($pse->getProductId())->getTitle();
$attributeCombination = AttributeCombinationQuery::create()->findOneByProductSaleElementsId($product->getPseId());
$unity = AttributeAvI18nQuery::create()->findOneById($attributeCombination->getAttributeAvId())->getTitle();
$inStock = $pse->getQuantity();
try {
$pse = ProductSaleElementsQuery::create()->findOneById($product->getPseId());
$productId = $pse->getProductId();
$productLabel = ProductI18nQuery::create()->findOneById($pse->getProductId())->getTitle();
$attributeCombination = AttributeCombinationQuery::create()->findOneByProductSaleElementsId($product->getPseId());
if ($attributeCombination)
$unity = AttributeAvI18nQuery::create()->findOneById($attributeCombination->getAttributeAvId())->getTitle();
else
$unity = "Pas de déclinaison";
$inStock = $pse->getQuantity();
$loopResultRow = new LoopResultRow($product);
$loopResultRow
->set("RECIPE_ID", $product->getRecipeId())
->set("PSE_ID", $product->getPseId())
->set("PRODUCT_ID", $productId)
->set("IN_STOCK", $inStock > 0)
->set("PRODUCT_LABEL", $productLabel)
->set("QUANTITY_NEEDED", $product->getQuantity())
->set("QUANTITY_PROPOSED", $product->getNbOfProducts())
->set('UNITY', $unity)
;
$loopResult->addRow($loopResultRow);
$loopResultRow = new LoopResultRow($product);
$loopResultRow
->set("RECIPE_ID", $product->getRecipeId())
->set("PSE_ID", $product->getPseId())
->set("PRODUCT_ID", $productId)
->set("IN_STOCK", $inStock > 0)
->set("PRODUCT_LABEL", $productLabel)
->set("QUANTITY_NEEDED", $product->getQuantity())
->set("QUANTITY_PROPOSED", $product->getNbOfProducts())
->set('UNITY', $unity)
;
$loopResult->addRow($loopResultRow);
}
catch (PropelException $e) {
throw new PropelException("Erreur dans l'alimentation de la ProductsLoop : " . $e);
}
}
return $loopResult;
}