THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline


Bon jour!
Pardon pour mon francais, je suis ukranien. J'ai besoin d'aide avec Thelia.

J'ai essayais de register un Loop dans nouveau module mais Thelia il ne detectait pas.

J'ai créé un module par le command line: "php Thelia module:generate ModuleName". Apres j'ai créé le class Myloop dans le Loop dir. J'ai utilisais cette link comme example: http://doc.thelia.net/en/documentation/ … loops.html . Apres j'ai registré le nouveau loop dans le config.xml de mon module.

Mais le loop n'etait ajoutait pas. Comment je peux cherche pourqui j'ai cette probleme?

Le code (Choicer - mon module):

    <loops>
        <loop name="Feat" class="Choicer\Loop\Feat" />
    </loops>
 <?php
 
namespace Choicer\Loop;

 use Thelia\Core\Template\Element\BaseLoop;
 use Thelia\Core\Template\Element\LoopResult;
 use Thelia\Core\Template\Element\LoopResultRow;
 use Thelia\Core\Template\Element\ArraySearchLoopInterface;
 use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
 use Thelia\Core\Template\Loop\Argument\Argument;

 class Feat extends BaseLoop implements ArraySearchLoopInterface {

    public $countable = true;
    public $timestampable = false;
    public $versionable = false;

     public function getArgDefinitions()
     {
         return new ArgumentCollection(
             Argument::createIntListTypeArgument('start', 0),
             Argument::createIntListTypeArgument('stop', null, true)
         );
     }

     public function buildArray()
     {
         $items = array();

         $start = $this->getStart();
         $stop = $this->getStop();

         for($i=$start; $i<=$stop; $i++ {
            $items[] = $i;
         }

         return $items;

     }

     public function parseResults(LoopResult $loopResult)
     {
         foreach ($loopResult->getResultDataCollection() as $item) {

             $loopResultRow = new LoopResultRow();

             $loopResultRow->set("MY_OUTPUT", $item);

             $loopResult->addRow($loopResultRow);
         }

         return $loopResult;
     }
 }

Last edited by Vdomah (07-11-2014 21:57:15)

Online


Il faut vider le cache.

Ceci dit,  tu peux écrire très facilement cette boucle en Smarty plutôt que de la coder: http://www.smarty.net/docs/en/language.function.for.tpl


OpenStudio Toulouse

Offline


roadster31 wrote:

Il faut vider le cache.

Si, apres elimination du cahce le loop etait detecte. Merci!

Mais je pance que cette instruction doit etre dans le documentation parce que ce ne pas évidemment pour les débutants avec Thelia.

Offline


D'autre question, s'il vous plait. Avec un model, comment je peux changer le model qui le loop utise? Pour example j'ai le FeatureAvailability loop avec

public function parseResults(LoopResult $loopResult)
    {
        foreach ($loopResult->getResultDataCollection() as $featureAv) {

Et je veux $loopResult->getResultDataCollection() à return des objects de mon nouveau model.

En general, je veux créer un module qui fait le cherche dans le catalogue en utilisant les features. Le features seront aux base des catégories comme les lists clickables. Je pense, que quelque module avec les functions similair peut déjà etre. Peut-etre vous savais quelque chose?

Last edited by Vdomah (24-10-2014 10:43:06)

Online


$loopResult->getResultDataCollection() retourne les objets qui résultent de la query créée dans la méthode buildModelCriteria().

Si ton nouveau modèle s'appelle MonNouveauModel, tu dois construire dans buildModelCriteria() une query de type MonNouveauModelQuery, et $loopResult contiendra donc des instances de MonNouveauModel.


OpenStudio Toulouse

Offline


Merci, j'ai tout compri maintenant.

Offline


Encor des questions.

J' essaye de suivre votres instructions sur nouveau model creation. Dans mon module j'ai créé de modeles Category et CategoryQuery avec l'héritage de Category et CategoryQuery du core. Dans le CategoryQuery j'ai changé le model dans le create methode comme ça

$query->modelName = '\\Filter\\Model\\Category';

Mais apres j'ai une error:

TableNotFoundException: Cannot fetch TableMap for undefined table phpName: \Filter\Model\Category.

Peut-etre il i a d'autre chemin de faire cette operation?

UPD: autre chemin de definir le model - hériter le __construct et changer le deuxième argument:

public function __construct($dbName = 'thelia', $modelName = '\\Filter\\Model\\Category', $modelAlias = null)

Mais aussi ce ne marche pas.

Last edited by Vdomah (02-11-2014 18:27:56)

Online


En surchargeant le modèle du core, qu'essaie-tu de faire ?


OpenStudio Toulouse

Offline


Pas beaucoup:
dans le create methode changé \Thelia\Model\CategoryQuery -> \Filter\Model\CategoryQuery
dans le __construct: $modelName = '\\Thelia\\Model\\Category' -> $modelName = '\\Filter\\Model\\Category'

namespace Filter\Model;

use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Model\CategoryQuery as CoreCategoryQuery;

class CategoryQuery extends CoreCategoryQuery
{

    public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof \Filter\Model\CategoryQuery) {
            return $criteria;
        }
        $query = new \Filter\Model\CategoryQuery();
        //$query->modelName = '\\Filter\\Model\\Category';
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }

    public function __construct($dbName = 'thelia', $modelName = '\\Filter\\Model\\Category', $modelAlias = null)
    {
        parent::__construct($dbName, $modelName, $modelAlias);
    }
namespace Filter\Model;

use Thelia\Model\Category as CoreCategory;

class Category extends CoreCategory
{}

Last edited by Vdomah (03-11-2014 09:08:58)

Online


Why are you doing this ? What are you trying to do ?


OpenStudio Toulouse

Offline


I want only to inherit the Category model to have ability to add my functionality. I understand that creating two new classes looks like not very effective way to solve that. But I don't see other way to do it within Thelia. What is the right way?

Online


To do that, you have to create your own model (tables and classes), which contains the data you wish to add to the standard Category table, and link it to the code Category table using a foreign key.


OpenStudio Toulouse

Offline


Thanks, now I've generated models and sql by command line, got new table filter_category in DB with fk named category_id and necessary files in Filter/Model dir.

Next obstacle is that Virtual Columns of hte model are not available. I've found that the problem is in this place:

public function buildModelCriteria()
{
        $search = FilterCategoryQuery::create();

        $search_category = $search->useCategoryQuery();

        /* manage translations */
        $this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION', 'META_KEYWORDS'), 'category', 'category_id');

So guessing I must properly change the parameters of configureI18nProcessing method.
Tried the following analyzing the signature.

protected function configureI18nProcessing(ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID', $forceReturn = false)

Changing the $search parameter and adding $foreignTable = 'category' and $foreignKey = 'category_id'. But nothing worked.

$this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION', 'META_KEYWORDS'));
$this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION', 'META_KEYWORDS'), 'category', 'category_id');
$this->configureI18nProcessing($search_category , array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION', 'META_KEYWORDS'));
$this->configureI18nProcessing($search_category , array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION', 'META_KEYWORDS'), 'category', 'category_id');

Last edited by Vdomah (05-11-2014 18:46:45)

Offline


Or is it required to create my table _i18n even if I don't use translated fields in new module?

Offline


About configureI18nProcessing: number two with 2 new arguments was right. Just neede some config. Strange that there doesn't exist some tutorial with this steps described. Or may be somewhere it exists?