THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

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

Offline


En se connectant avec un acheteur1, .../web/account/order/1 fonction. Par contre, lorsque l'on se connecte avec l'acheteur2 .../web/account/order/5 affiche une erreur 403.

J'ai modifié le code du template :

{extends file="layout.tpl"}

{* Security *}
{block name="no-return-functions" prepend}
{check_auth role="CUSTOMER" login_tpl="login"}
{/block}

{* Breadcrumb *}
{block name='no-return-functions' append}
{$breadcrumbs = [
['title' => {intl l="Account"}, 'url'=>{url path="/account"}],
['title' => {intl l="Order details"}, 'url'=>{url path="/account/order/%order_id" order_id=$order_id}]
]}
{/block}

{block name="body-class"}page-account-order{/block}

{block name="main-content"}
<div class="main">

    {loop name="order" type="ampseller_order" customer="current" id="$order_id" limit="1" }

    {$payment_id=$PAYMENT_MODULE}
    {$delivery_id=$DELIVERY_MODULE}
    {$status=$STATUS}

    <article class="col-main" role="main" aria-labelledby="main-label">

        <h1 id="main-label" class="page-header">{intl l="Order details %ref" ref={$REF}}</h1>

        {hook name="account-order.top" order={$order_id}}

        {* Infos *}
        <dl class="order-information dl-horizontal">
            <dt>{intl l="Seller"}</dt>
            <dd>{$AMP_SELLER_NAME}</dd>
            <dt>{intl l="REF"}</dt>
            <dd>{$REF}</dd>

            <dt>{intl l="Created"}</dt>
            <dd>{format_date date=$CREATE_DATE output="datetime"}</dd>

            <dt>{intl l="Status"}</dt>
            <dd>{loop type="order-status" name="order_status" id=$STATUS}{$TITLE}{/loop}</dd>

            {if $IS_PAID}
                <dt>{intl l="Invoice date"}</dt>
                <dd>{format_date date=$INVOICE_DATE output="date"}</dd>

                {if $INVOICE_REF}
                <dt>{intl l="Invoice REF"}</dt>
                <dd>{$INVOICE_REF}</dd>
                {/if}

                <dt>{intl l="PDF invoice"}</dt>
                <dd><a href="{url path="/account/order/pdf/invoice/%id" id=$ID}">{intl l="Download"}</a></dd>
            {/if}
            {if $DELIVERY_REF}
                <dt>{intl l="Delivery REF"}</dt>
                <dd>{$DELIVERY_REF}</dd>
            {/if}
            <dt>{intl l="Customer Number"}</dt>
            <dd>{loop type="customer" name="customer.invoice" id=$CUSTOMER current="0"}{$REF}{/loop}</dd>

            {hookblock name="account-order.information" order={$order_id} fields="title,value"}
            {forhook rel="account-order.information"}
                <dt>{$title}</dt>
                <dd>{$value}</dd>
            {/forhook}
            {/hookblock}
        </dl>

        {hook name="account-order.after-information" order={$order_id}}

        {* Addresses *}
        <div id="order-addresses" class="row">
            <div class="col-md-6 col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">{intl l="Delivery"}</div>
                    <div class="panel-body">
                        <h4>{intl l="Delivery Mode"}</h4>
                        {ifhook rel="account-order.delivery-information"}
                            {hook name="account-order.delivery-information" module={$delivery_id} order={$order_id}}
                        {/ifhook}
                        {elsehook rel="account-order.delivery-information"}
                            <p>{loop name="delivery-module" type="module" id=$DELIVERY_MODULE}{$TITLE}{/loop}</p>
                        {/elsehook}

                        <h4>{intl l="Address"}</h4>

                        {ifhook rel="account-order.delivery-address"}
                            {* delivery module can customize the delivery address *}
                            {hook name="account-order.delivery-address" module={$delivery_id} order={$order_id}}
                        {/ifhook}
                        {elsehook rel="account-order.delivery-address"}
                            {format_address order_address=$DELIVERY_ADDRESS}
                        {/elsehook}

                        {hook name="account-order.delivery-address-bottom" module={$delivery_id} order={$order_id}}
                    </div>
                </div>
            </div>
            <div class="col-md-6 col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">{intl l="Billing"}</div>
                    <div class="panel-body">
                        <h4>{intl l="Payment Mode"}</h4>
                        {ifhook rel="account-order.invoice-information"}
                            {hook name="account-order.invoice-information" module={$payment_id} order={$order_id}}
                        {/ifhook}
                        {elsehook rel="account-order.invoice-information"}
                            <p>{loop name="payment-module" type="module" id=$PAYMENT_MODULE}{$TITLE}{/loop}</p>
                            {if $TRANSACTION_REF}
                            <p>{intl l="Transaction REF : %ref" ref={$TRANSACTION_REF}}</p>
                            {/if}
                        {/elsehook}

                        <h4>{intl l="Address"}</h4>

                        {ifhook rel="account-order.invoice-address"}
                            {* payment module can customize the delivery address *}
                            {hook name="account-order.invoice-address" module={$payment_id} order={$order_id}}
                        {/ifhook}
                        {elsehook rel="account-order.invoice-address"}
                            {format_address order_address=$INVOICE_ADDRESS}
                        {/elsehook}

                        {hook name="account-order.invoice-address-bottom" module={$payment_id} order={$order_id}}
                    </div>
                </div>
            </div>
        </div>

        {hook name="account-order.after-addresses" order={$order_id}}

        {* products *}
        <table class="table table-order table-bordered order-products">
            <thead>
                <tr>
                    <th class="product">
                        <span class="hidden-xs">{intl l="Product Name"}</span>
                        <span class="visible-xs">{intl l="Name"}</span>
                    </th>
                    <th class="unitprice">
                        <span class="hidden-xs">{intl l="Unit Price"}</span>
                        <span class="visible-xs">{intl l="Price"}</span>
                    </th>
                    <th class="unitprice">
                        <span class="hidden-xs">{intl l="Unit Taxed Price"}</span>
                        <span class="visible-xs">{intl l="Taxed Price"}</span>
                    </th>
                    <th class="qty">
                        <span class="hidden-xs">{intl l="Quantity"}</span>
                        <span class="visible-xs">{intl l="Qty"}</span>
                    </th>
                    <th class="subprice">
                        <span class="hidden-xs">{intl l="Total"}</span>
                        <span class="visible-xs">{intl l="Total"}</span>
                    </th>
                </tr>
            </thead>
            <tbody>

            {ifhook rel="account-order.products-top"}
            <tr>
                <td class="products-top" colspan="5">
                    {hook name="account-order.products-top" order={$order_id}}
                </td>
            </tr>
            {/ifhook}

            {loop type="order_product" name="order-products" order="$ORDER_ID" id="$ORDER_PRODUCT_ID"}
                {if $WAS_IN_PROMO == 1}
                    {assign "realPrice" $PROMO_PRICE}
                    {assign "realTax" $PROMO_PRICE_TAX}
                    {assign "realTaxedPrice" $TAXED_PROMO_PRICE}
                    {assign "realTotalPrice" $TOTAL_TAXED_PROMO_PRICE}
                {else}
                    {assign "realPrice" $PRICE}
                    {assign "realTax" $PRICE_TAX}
                    {assign "realTaxedPrice" $TAXED_PRICE}
                    {assign "realTotalPrice" $TOTAL_TAXED_PRICE}
                {/if}

                {$taxes[{$TAX_RULE_TITLE}][] = $realTax * $QUANTITY}

                <tr data-id={$ID}  data-product-id={$PRODUCT_ID} data-pse-id={$PRODUCT_SALE_ELEMENTS_ID}>
                    <td class="product" >
                        <p>{$TITLE}</p>
                        {ifloop rel="combinations"}
                        <p>
                        {loop type="order_product_attribute_combination" name="combinations" order_product=$ID}
                            {$ATTRIBUTE_TITLE} - {$ATTRIBUTE_AVAILABILITY_TITLE}<br>
                        {/loop}
                        </p>
                        {/ifloop}
                        {hook name="account-order.product-list" order_id={$order_id} order_product_id={$ID} product={$PRODUCT_ID}}
                    </td>
                    <td class="unitprice"><p>{format_money number=$realPrice currency_id=$CURRENCY}</p></td>
                    <td class="unitprice"><p>{format_money number=$realTaxedPrice currency_id=$CURRENCY}</p></td>
                    <td class="qty"><p>{$QUANTITY}</p></td>
                    <td class="subprice"><p>{format_money number=$realTotalPrice currency_id=$CURRENCY}</p></td>
                </tr>
                {ifhook rel="account-order.product-extra"}
                <tr>
                    <td class="product-extra" colspan="5">
                        {hook name="account-order.product-extra" order={$order_id} order_product={$ID} product={$PRODUCT_ID}}
                    </td>
                </tr>
                {/ifhook}
            {/loop}

            {ifhook rel="account-order.products-bottom"}
            <tr>
                <td class="products-bottom" colspan="5">
                    {hook name="account-order.products-bottom" order={$order_id}}
                </td>
            </tr>
            {/ifhook}

            </tbody>
        </table>

        {hook name="account-order.after-products" order={$order_id}}

        <div class="row">
            <div class="col-md-6 col-md-offset-6 col-sm-9 col-sm-offset-3 col-xs-12">
                <table class="table order-total table-order table-bordered table-order-total">
                    <tfoot>
                        {if $DISCOUNT}
                        <tr>
                            <td><p>{intl l="Discount"}</p></td>
                            <td><p>{format_money number=$DISCOUNT currency_id=$CURRENCY}</p></td>
                        </tr>
                        {/if}
                        <tr>
                            <td><p>{intl l="Total without tax"}</p></td>
                            <td><p>{format_money number={$TOTAL_UNTAXED_AMOUNT} currency_id=$CURRENCY}</p></td>
                        </tr>
                        {strip}
                            {capture name="tax"}
                                {foreach $taxes as $name=>$prices}
                                    {assign var="_price_taxe_" value="0"}
                                    {foreach $prices as $price}
                                        {$_price_taxe_= $_price_taxe_ + $price}
                                    {/foreach}
                                    {if $_price_taxe_ != 0}
                                    <tr>
                                        <td><p>{$name}</p></td>
                                        <td><P>{format_money number=$_price_taxe_ currency_id=$CURRENCY}</P></td>
                                    </tr>
                                    {/if}
                                {/foreach}
                            {/capture}
                        {/strip}
                        {if $smarty.capture.tax ne ""}
                            {$smarty.capture.tax nofilter}
                        {/if}
                        <tr>
                            <td><p>{intl l="Total with tax"}</p></td>
                            <td><P>{format_money number={$TOTAL_TAXED_AMOUNT} currency_id=$CURRENCY}</P></td>
                        </tr>
                        <tr>
                            <td><p>{intl l="Postage"}</p></td>
                            <td><p>{format_money number=$POSTAGE curency_id=$CURRENCY}</p></td>
                        </tr>
                        <tr>
                            <td><h3>{intl l="Total"}</h3></td>
                            <td><h3>{format_money number=$TOTAL_TAXED_AMOUNT_POSTAGE currency_id=$CURRENCY}</h3></td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>

        {hook name="account-order.bottom" order={$order_id}}

    </article>

    {/loop}

</div>
{/block}

{block name="stylesheet"}
{hook name="account-order.stylesheet"}
{/block}

{block name="after-javascript-include"}
{hook name="account-order.after-javascript-include" order=$order_id}
{/block}

{block name="javascript-initialization"}
{hook name="account-order.javascript-initialization" order=$order_id}
{/block}

Une piste ?

Offline


Bon, je trouve toujours pas...

Voici le code de ma loop ampseller_order...

<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace ArtabanMarketplace\Loop;

use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Element\SearchLoopInterface;
use ArtabanMarketplace\Model\Map\AmpSellerOrderTableMap;
use ArtabanMarketplace\Model\AmpSellerOrderQuery;
use ArtabanMarketplace\Model\AmpSellerQuery;
use ArtabanMarketplace\Model\AmpSellerAdminQuery;
use ArtabanMarketplace\Model\AmpSellerOrderAddressQuery;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Order;
use Thelia\Model\OrderQuery;
use Thelia\Model\AdminQuery;
use Thelia\Model\Map\OrderTableMap;
use Propel\Runtime\Propel;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Type;
use Thelia\Type\TypeCollection;
use ArtabanMarketplace\Model\AmpSellerOrderDeliveryReferenceQuery;

/**
 * Description of AmpSellerOrderLoop
 *
 * @author LENGY Gilles
 */
class AmpSellerOrderLoop extends BaseLoop implements SearchLoopInterface, PropelSearchLoopInterface {

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

    /**
     * @inheritDoc
     */
    protected function getArgDefinitions() {
        return new ArgumentCollection(
                Argument::createIntListTypeArgument('id'), Argument::createIntListTypeArgument('amp_seller_id'), Argument::createIntListTypeArgument('customer_id'), Argument::createIntListTypeArgument('order_id'), Argument::createAlphaNumStringTypeArgument('interval_creation_order'), new Argument(
                'customer', new TypeCollection(
                new Type\IntType(), new Type\EnumType(array('current', '*'))
                ), NULL
                )
        );
    }

    public function parseResults(LoopResult $loopResult) {
        /**  @var ArtabanMarketplace\Model\AmpSellerOrder $sellerOrder */
        foreach ($loopResult->getResultDataCollection() as $sellerOrder) {

            $sellerOrderQuery = new AmpSellerOrderQuery();
            $sellerOrderObject = $sellerOrderQuery->findOneById($sellerOrder->getId());

            if ($sellerOrderObject !== NULL) {

                // Seller Name
                $sellerQuery = new AmpSellerQuery();
                $seller = $sellerQuery->findOneById($sellerOrderObject->getAmpSellerId());

                $sellerAdminQuery = new AmpSellerAdminQuery();
                $sellerAdmin = $sellerAdminQuery->findOneByAmpSellerId($seller->getId());

                $adminQuery = new AdminQuery();
                $admin = $adminQuery->findOneById($sellerAdmin->getAdminId());

                $sellerName = $admin->getFirstname() . " " . $admin->getLastname();

                // Order            
                $orderQuery = new orderQuery();
                $order = $orderQuery->findOneById($sellerOrderObject->getOrderId());

                // Amount, Tax
                $amountTaxArray = $sellerOrderObject->getAmountTax($sellerOrderObject->getId(), $sellerOrderObject->getOrderId());
                $totalTax = $amountTaxArray["total_tax"];
                $totalTaxedAmount = $amountTaxArray["total_amount"] + $totalTax;
                $totalUntaxedAmount = $amountTaxArray["total_amount"];
                $totalTaxedAmountPostage = $totalTaxedAmount + $sellerOrderObject->getPostage();
                
                // Delivery Ref
                $sellerOrdereliveryRefQuery =  new AmpSellerOrderDeliveryReferenceQuery();
                $sellerOrdereliveryRef = $sellerOrdereliveryRefQuery->findOneByOrderSellerId($sellerOrderObject->getId());
                
            }

            $loopResultRow = new LoopResultRow($order);
            $loopResultRow
                    ->set('ID', $sellerOrderObject->getId())
                    ->set('REF', $sellerOrderObject->getSellerOrderRef())
                    ->set('CUSTOMER', $order->getCustomerId())
                    ->set('ORDER_PRODUCT_ID', $sellerOrderObject->getOrderProductId())
                    ->set('ORDER_ID', $sellerOrderObject->getOrderId())
                    ->set('DELIVERY_ADDRESS', $order->getDeliveryOrderAddressId())
                    ->set('INVOICE_ADDRESS', $order->getInvoiceOrderAddressId())
                    ->set('INVOICE_DATE', $order->getInvoiceDate())
                    ->set('CURRENCY', $order->getCurrencyId())
                    ->set('CURRENCY_RATE', $order->getCurrencyRate())
                    ->set('TRANSACTION_REF', $order->getTransactionRef())
                    ->set('INVOICE_REF', $sellerOrderObject->getSellerOrderRef())
                    ->set('VIRTUAL', $hasVirtualDownload)
                    ->set('POSTAGE', $sellerOrderObject->getPostage())
                    ->set('POSTAGE_TAX', $sellerOrderObject->getPostageTax())
                    ->set('POSTAGE_UNTAXED', $sellerOrderObject->getUntaxedPostage())
                    ->set('POSTAGE_TAX_RULE_TITLE', $order->getPostageTaxRuleTitle())
                    ->set('PAYMENT_MODULE', $order->getPaymentModuleId())
                    ->set('DELIVERY_MODULE', $order->getDeliveryModuleId())
                    ->set('STATUS', $order->getStatusId())
                    ->set('STATUS_CODE', $order->getOrderStatus()->getCode())
                    ->set('LANG', $order->getLangId())
                    ->set('DISCOUNT', $sellerOrderObject->getDiscount())
                    ->set('TOTAL_TAX', $totalTax)
                    ->set('TOTAL_UNTAXED_AMOUNT', $totalUntaxedAmount)
                    ->set('TOTAL_TAXED_AMOUNT', $totalTaxedAmount)
                    ->set('TOTAL_TAXED_AMOUNT_POSTAGE', $totalTaxedAmountPostage)
                    ->set('WEIGHT', $sellerOrderObject->getWeight($sellerOrderObject->getId(), $sellerOrderObject->getOrderId()))
                    ->set('HAS_PAID_STATUS', $order->isPaid())
                    ->set('IS_PAID', $order->isPaid(false))
                    ->set('IS_CANCELED', $order->isCancelled())
                    ->set('IS_NOT_PAID', $order->isNotPaid())
                    ->set('IS_SENT', $order->isSent())
                    ->set('IS_PROCESSING', $order->isProcessing())
            ;

            if ($sellerOrder !== NULL) {
                $loopResultRow
                        ->set('SELLER_ORDER_ID', $sellerOrder->getOrderId())
                        ->set('ORDER_ID', $sellerOrder->getOrderId())
                        ->set('AMP_SELLER_ID', $seller->getId())
                        ->set('AMP_SELLER_NAME', $sellerName);
            }
            if ($sellerOrdereliveryRef !== NULL) {
                $loopResultRow
                        ->set('DELIVERY_REF', $sellerOrdereliveryRef->getDeliveryReference());
            }

            $this->addOutputFields($loopResultRow, $order);

            $loopResult->addRow($loopResultRow);
        }

        return $loopResult;
    }

    /**
     * @inheritdoc
     */
    public function buildModelCriteria() {
        $query = AmpSellerOrderQuery::create();

        if (null != $id = $this->getId()) {
            $query->filterById($id);
        }

        if (null != $amp_seller_id = $this->getAmpSellerId()) {
            $query->filterByAmpSellerId($amp_seller_id);
        }

        if (null != $customer_id = $this->getCustomerId()) {
            $query->filterByCustomerId($customer_id);
        }

        if (null != $order_id = $this->getOrderId()) {
            $query->filterByOrderId($order_id);
        }

        if (null != $customer = $this->getCustomer()) {


            if ($customer === 'current') {
                $currentCustomer = $this->securityContext->getCustomerUser();
                if ($currentCustomer === null) {
                    return null;
                } else {
                    $query->filterByCustomerId($currentCustomer->getId(), Criteria::EQUAL);
                }
            } elseif ($customer !== '*') {
                $query->filterByCustomerId($customer, Criteria::EQUAL);
            }
        }

        if (null != $intervalCreationOrder = $this->getIntervalCreationOrder()) {
            if ($intervalCreationOrder === 'today') {
                $query->filterByCreatedAt(array(
                    'min' => 'today'
                ));
            }
            if ($intervalCreationOrder === 'yesterday') {
                $query->filterByCreatedAt(array(
                    'min' => 'yesterday',
                    'max' => 'today'
                ));
            }
            if ($intervalCreationOrder === 'this_month') {
                $beginingThisMonth = mktime(0, 0, 0, date("m"), 01, date("Y"));
                $query->filterByCreatedAt(array(
                    'min' => $beginingThisMonth
                ));
            }
            if ($intervalCreationOrder === 'previous_month') {
                $beginingPreviousMonth = mktime(0, 0, 0, date("m") - 1, 01, date("Y"));
                $endPreviousMonth = mktime(0, 0, 0, date("m"), 01, date("Y")) - (24 * 60 * 60);
                $query->filterByCreatedAt(array(
                    'min' => $beginingPreviousMonth,
                    'max' => $endPreviousMonth
                ));
            }
            if ($intervalCreationOrder === 'this_year') {
                $beginingThisYear = mktime(0, 0, 0, 01, 01, date("Y"));
                $query->filterByCreatedAt(array(
                    'min' => $beginingThisYear
                ));
            }
            if ($intervalCreationOrder === 'previous_year') {
                $beginingPreviousYear = mktime(0, 0, 0, 01, 01, date("Y") - 1);
                $endPreviousYear = mktime(0, 0, 0, 12, 31, date("Y") - 1);
                $query->filterByCreatedAt(array(
                    'min' => $beginingThisYear,
                    'max' => $endPreviousYear
                ));
            }
        }
        return $query;
    }

    public function getSearchIn() {
        return array(
//            'ref',
//            'invoice_ref',
//            'delivery_ref',
//            'transaction_ref',
//            'customer_ref',
//            'customer_firstname',
//            'customer_lastname',
//            'customer_email',
        );
    }

    /**
     * @param AmpSellerOrderQuery $search
     * @param $searchTerm
     * @param $searchIn
     * @param $searchCriteria
     */
    public function doSearch(&$search, $searchTerm, $searchIn, $searchCriteria) {
//        $search->_and();
//        foreach ($searchIn as $index => $searchInElement) {
//            if ($index > 0) {
//                $search->_or();
//            }
//            switch ($searchInElement) {
//                case 'ref':
//                    $search->filterByRef($searchTerm, $searchCriteria);
//                    break;
//                case 'invoice_ref':
//                    $search->filterByInvoiceRef($searchTerm, $searchCriteria);
//                    break;
//                case 'delivery_ref':
//                    $search->filterByDeliveryRef($searchTerm, $searchCriteria);
//                    break;
//                case 'transaction_ref':
//                    $search->filterByTransactionRef($searchTerm, $searchCriteria);
//                    break;
//                case 'customer_ref':
//                    $search->filterByCustomer(
//                            CustomerQuery::create()->filterByRef($searchTerm, $searchCriteria)->find()
//                    );
//                    break;
//                case 'customer_firstname':
//                    $search->filterByOrderAddressRelatedByInvoiceOrderAddressId(
//                            AmpSellerOrderAddressQuery::create()->filterByFirstname($searchTerm, $searchCriteria)->find()
//                    );
//                    break;
//                case 'customer_lastname':
//                    $search->filterByOrderAddressRelatedByInvoiceOrderAddressId(
//                            AmpSellerOrderAddressQuery::create()->filterByLastname($searchTerm, $searchCriteria)->find()
//                    );
//                    break;
//                case 'customer_email':
//                    $search->filterByCustomer(
//                            CustomerQuery::create()->filterByEmail($searchTerm, $searchCriteria)->find()
//                    );
//                    break;
//            }
//        }
    }

}

Si vous voyez quelque chose...

Je vais voir au niveau du controlleur...

Offline


Finalement, j'ai créé un controller qui appelle un template spécifique à mes commandes marchands. Je pense que c'est plus logique que de tenter d'utiliser le template des commandes thelia ordinaire... Pour les petits malin qui voudrait utiliser l'url pour les commande ordinaire, j'ai mis un message "Accès interdit" !