THELIA Forum

Welcome to the THELIA support and discusssion forum

Offline


J'ai réussi à commencer à implémenter le système standart de gestion des images pour un objet donné. L'ajout se passe bien. Le réordonement aussi. Par contre, pas moyen d'effacer une image.

Voici les bout de code :

ArtabanMarketplace\templates\backOffice\default\includes\seller-image-upload-list-ajax.html

....
<a class="image-delete-btn btn btn-default btn-xs" id="image-{$ID}" href="{url path="/admin/module/artabanmarketplace/seller_image/delete/{$ID}"}" data-error-message="{intl l='Please retry'}">
<span class="glyphicon glyphicon-trash"></span>
</a>
....

ArtabanMarketplace\Config\routing.xml

....
    <route id="ArtabanMarketplace.seller_image.delete" path="/admin/module/artabanmarketplace/seller_image/delete/{imageId}" methods="post">
        <default key="_controller">ArtabanMarketplace:SellerImage:deleteImage</default>
        <requirement key="imageId">\d+</requirement>
    </route>
....

ArtabanMarketplace\Controller\SellerImageController.php

....
    public function deleteImageAction($imageId)
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth($this->resourceCode, $this->getModuleCode(), AccessManager::DELETE)) {
            return $response;
        }
          
        try {
            $seller_image = AmpSellerImageQuery::create()->findPk($imageId);
            $event = new AmpSellerImageEvent($imageId);
            $event->setId($imageId);
            $this->dispatch($this->deleteEventIdentifier, $event);
            $this->performAdditionalDeleteAction($event);
            return $this->generateRedirect($seller_image->getRedirectionUrl());
        } catch (\Exception $e) {
            return $this->renderAfterDeleteError($e);
        }
    }
....

ArtabanMarketplace\Event\AmpSellerImageEvent.php

....
namespace ArtabanMarketplace\Event;

use ArtabanMarketplace\Event\Base\AmpSellerImageEvent as BaseAmpSellerImageEvent;

/**
 * Class AmpSellerImageEvent
 * @package ArtabanMarketplace\Event
 */
class AmpSellerImageEvent extends BaseAmpSellerImageEvent
{
}

ArtabanMarketplace\Event\Base\AmpSellerImageEvent.php

....
namespace ArtabanMarketplace\Event\Base;

use Thelia\Core\Event\ActionEvent;
use ArtabanMarketplace\Model\AmpSellerImage;

/**
* Class AmpSellerImageEvent
* @package ArtabanMarketplace\Event\Base
*/
class AmpSellerImageEvent extends ActionEvent
{
    protected $id;
    protected $ampSellerId;
    protected $file;
    protected $visible;
    protected $position;
    protected $title;
    protected $description;
    protected $chapo;
    protected $postscriptum;
    protected $ampSellerImage;
    protected $locale;

    public function getLocale()
    {
        return $this->locale;
    }

    public function setLocale($v)
    {
        $this->locale = $v;

        return $this;
    }

    public function getId()
    {
        return $this->id;
    }

    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }

    public function getAmpSellerId()
    {
        return $this->ampSellerId;
    }

    public function setAmpSellerId($ampSellerId)
    {
        $this->ampSellerId = $ampSellerId;

        return $this;
    }

    public function getFile()
    {
        return $this->file;
    }

    public function setFile($file)
    {
        $this->file = $file;

        return $this;
    }

    public function getVisible()
    {
        return $this->visible;
    }

    public function setVisible($visible)
    {
        $this->visible = $visible;

        return $this;
    }

    public function getPosition()
    {
        return $this->position;
    }

    public function setPosition($position)
    {
        $this->position = $position;

        return $this;
    }

    public function getTitle()
    {
        return $this->title;
    }

    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    public function getDescription()
    {
        return $this->description;
    }

    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    public function getChapo()
    {
        return $this->chapo;
    }

    public function setChapo($chapo)
    {
        $this->chapo = $chapo;

        return $this;
    }

    public function getPostscriptum()
    {
        return $this->postscriptum;
    }

    public function setPostscriptum($postscriptum)
    {
        $this->postscriptum = $postscriptum;

        return $this;
    }

    public function getAmpSellerImage()
    {
        return $this->ampSellerImage;
    }

    public function setAmpSellerImage(AmpSellerImage $ampSellerImage)
    {
        $this->ampSellerImage = $ampSellerImage;

        return $this;
    }
}

ArtabanMarketplace\Model\Base\AmpSellerImageQuery.php

....

    /**
     * Initializes internal state of \ArtabanMarketplace\Model\Base\AmpSellerImageQuery object.
     *
     * @param     string $dbName The database name
     * @param     string $modelName The phpName of a model, e.g. 'Book'
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
     */
    public function __construct($dbName = 'thelia', $modelName = '\\ArtabanMarketplace\\Model\\AmpSellerImage', $modelAlias = null)
    {
        parent::__construct($dbName, $modelName, $modelAlias);
    }

    /**
     * Returns a new ChildAmpSellerImageQuery object.
     *
     * @param     string $modelAlias The alias of a model in the query
     * @param     Criteria $criteria Optional Criteria to build the query from
     *
     * @return ChildAmpSellerImageQuery
     */
    public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof \ArtabanMarketplace\Model\AmpSellerImageQuery) {
            return $criteria;
        }
        $query = new \ArtabanMarketplace\Model\AmpSellerImageQuery();
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }

    /**
     * Find object by primary key.
     * Propel uses the instance pool to skip the database if the object exists.
     * Go fast if the query is untouched.
     *
     * <code>
     * $obj  = $c->findPk(12, $con);
     * </code>
     *
     * @param mixed $key Primary key to use for the query
     * @param ConnectionInterface $con an optional connection object
     *
     * @return ChildAmpSellerImage|array|mixed the result, formatted by the current formatter
     */
    public function findPk($key, $con = null)
    {
        if ($key === null) {
            return null;
        }
        if ((null !== ($obj = AmpSellerImageTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) {
            // the object is already in the instance pool
            return $obj;
        }
        if ($con === null) {
            $con = Propel::getServiceContainer()->getReadConnection(AmpSellerImageTableMap::DATABASE_NAME);
        }
        $this->basePreSelect($con);
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
         || $this->map || $this->having || $this->joins) {
            return $this->findPkComplex($key, $con);
        } else {
            return $this->findPkSimple($key, $con);
        }
    }
....

Lorsque je clique pour effacer une image, après la confirmation, il y l'image de thelia pour dire que ça mouline qui tourne indéfiniment et dala console j'ai l'erreur suivante :

jquery-2.0.3.min.js:6 POST http://localhost/theliaArtabanMarketplace/web/index_dev.php/admin/module/artabanmarketplace/seller_image/delete/8 500 (Internal Server Error)

Je m'arrache les cheveux là dessous depuis plusieurs heures...
Toute aide est la bienvenue !

Merci d'avance !