Jump to content

Edit History

Leo-Sur

Leo-Sur

public function hookDisplayHome($params)
{
    $lang_id = (int) Configuration::get('PS_LANG_DEFAULT');

        // récupération de l'id Produit depuis le BO
    $id_product = Configuration::get('MYMODULE_CONFIG');

        // récupération produit
    $product = new Product($id_product, true, $lang_id); 
	 
	// prix TTC
    $price = $product->getPricesDrop($id_product);

    // $flags = discount::get();

    // Hook displayProductExtraContent
    // $extraContentFinder = new ProductExtraContentFinder();


        // image de couverture
    $image = Product::getCover($id_product); 
    $cover_url = $this->context->link->getImageLink($product->link_rewrite, $image['id_image'], ImageType::getFormatedName('large'));
    $other_img = $product->getImages($id_product);
    $product_img = [];
    foreach ($other_img as $img) {
        array_push($product_img, $this->context->link->getImageLink($product->link_rewrite, $img['id_image'], ImageType::getFormatedName('large')));  
    }

    $features = $product->getFrontFeatures($lang_id);
    $attachments = Attachment::getAttachments($lang_id, $id_product);
   
    if (Validate::isLoadedObject($product)) {

        $this->context->smarty->assign([
            'my_module_name' => Configuration::get('MYMODULE_NAME'),
            'product' => $product,

            'cover_url' => $cover_url,
            'product_img' => $product_img,

            'features' => $features,
            'attachments' => $attachments,

            'price' => $price,
          
        ]);

    }   
   
    return $this->display(__FILE__, 'mymodule.tpl');
}

partie monmodule.php au dessus, ou j'ai du "trafiqué" pour récupérer certaines données, comme le prix TTC que je récupère dans getPricesDrop,
 

et la partie product-prices.tpl
avec en commentaire les parties que je ne peux ajouter car je n'arrive pas a récupérer des variables, ou que je dois recréer au sein du module car elles nécessitent des -> au lieu de . dans le code.

 

{if $product->show_price}
  <div class="product-prices js-product-prices">
    {block name='product_discount'}
      {if $product->specificPrice}
        <div class="product-discount">
          {hook h='displayProductPriceBlock' product=$product type="old_price"}
          <span class="regular-price">{$price.0.price_without_reduction}€</span>
        </div>
      {/if}
    {/block}


    {block name='product_price'}
      <div
        class="product-price h5 {if $product->specificPrice}has-discount{/if}">

        <div class="current-price">
          <span class='current-price-value' content="{$product->price}">
            {capture name='custom_price'}{hook h='displayProductPriceBlock' product=$product type='custom_price' hook_origin='product_sheet'}{/capture}
            {if '' !== $smarty.capture.custom_price}
              {$smarty.capture.custom_price nofilter}
            {else}
            {$price.0.price}€
            {/if}
          </span>

          {if $product->specificPrice}
            {if $product->specificPrice.reduction_type === 'percentage'}
              <span class="discount discount-percentage">{l s='Save %percentage%' d='Shop.Theme.Catalog' sprintf=['%percentage%' => ($product->specificPrice.reduction * 100)]}% </span>
            {else}
              <span class="discount discount-amount">
                  {l s='Save %amount%' d='Shop.Theme.Catalog' sprintf=['%amount%' => $price.0.reduction]}€
              </span>
            {/if}
          {/if} 
        </div>

       {* {block name='product_unit_price'}
          {if $product->unit_price}
            <p class="product-unit-price sub">{l s='(%unit_price%)' d='Shop.Theme.Catalog' sprintf=['%unit_price%' => $product->unit_price]}</p>
          {/if}
        {/block}  *}
      </div>
    {/block}

    {* {block name='product_without_taxes'}
      {if $priceDisplay == 2}
        <p class="product-without-taxes">{l s='%price% tax excl.' d='Shop.Theme.Catalog' sprintf=['%price%' => $product.price_tax_exc]}</p>
      {/if}
    {/block} *}

    {* {block name='product_pack_price'}
      {if $displayPackPrice}
        <p class="product-pack-price"><span>{l s='Instead of %price%' d='Shop.Theme.Catalog' sprintf=['%price%' => $noPackPrice]}</span></p>
      {/if}
    {/block} *}

    {block name='product_ecotax'}
      {if $product->ecotax > 0}
        <p class="price-ecotax">{l s='Including %amount% for ecotax' d='Shop.Theme.Catalog' sprintf=['%amount%' => $product->ecotax]}
          {if $product->specificPrice}
            {l s='(not impacted by the discount)' d='Shop.Theme.Catalog'}
          {/if}
        </p>
      {/if}
    {/block}

    {hook h='displayProductPriceBlock' product=$product type="weight" hook_origin='product_sheet'}

    <div class="tax-shipping-delivery-label">
      {* {if !$configuration.taxes_enabled}
        {l s='No tax' d='Shop.Theme.Catalog'}
      {elseif $configuration.display_taxes_label}
        {$product.labels.tax_long}
      {/if} *}
      {hook h='displayProductPriceBlock' product=$product type="price"}
      {hook h='displayProductPriceBlock' product=$product type="after_price"}

             
      {if $product->is_virtual == 0}
        {* {if $product->additional_delivery_times == 1}
        {if $product.delivery_information}
            <span class="delivery-information">{$product.delivery_information}</span>
          {/if}
        {elseif $product->additional_delivery_times == 2} *}
          {if $product->quantity > 0}
            <span class="delivery-information">{$product->delivery_in_stock}</span>
          {* Out of stock message should not be displayed if customer can't order the product. *}
          {elseif $product->quantity <= 0 }
            <span class="delivery-information">{$product->delivery_out_stock}</span>
          {/if}
        {* {/if} *}
      {/if}
    </div>
  </div>
{/if}

 

Leo-Sur

Leo-Sur

public function hookDisplayHome($params)
{
    $lang_id = (int) Configuration::get('PS_LANG_DEFAULT');

        // récupération de l'id Produit depuis le BO
    $id_product = Configuration::get('MYMODULE_CONFIG');

        // récupération produit
    $product = new Product($id_product, 1, $lang_id); 

        // image de couverture
    $image = Product::getCover($id_product); 
    $cover_url = $this->context->link->getImageLink($product->link_rewrite, $image['id_image'], ImageType::getFormatedName('large'));
    $other_img = $product->getImages($id_product);
    $product_img = [];
    foreach ($other_img as $img) {
        array_push($product_img, $this->context->link->getImageLink($product->link_rewrite, $img['id_image'], ImageType::getFormatedName('large')));  
    }


    $features = $product->getFrontFeatures($lang_id);
    $attachments = Attachment::getAttachments($lang_id, $id_product);
   

   
    if (Validate::isLoadedObject($product)) {

        $this->context->smarty->assign([
            'my_module_name' => Configuration::get('MYMODULE_NAME'),
            'product' => $product,

            'cover_url' => $cover_url,
            'product_img' => $product_img,

            'features' => $features,
            'attachments' => $attachments,
          
        ]);

    }   
   
    return $this->display(__FILE__, 'mymodule.tpl');
}

partie monmudle.php au dessus,

 

et mon module.tpl, 
avec en commentaire les parties que je ne peux ajouter par manque de variable lié a product, ou que je dois recréer au sein du module car elles nécessitent des -> au lieu de . dans le code.

 

{block name='head' append}
  <meta property="og:type" content="product">
  {if $cover_url}
    <meta property="og:image" content="{$cover_url}">
  {/if}

{/block}

{dump($product)}

{block name='content'}

  <section id="main">
    <div class="row product-container js-product-container">
      <div class="col-md-6">
        {block name='page_content_container'}
          <section class="page-content" id="content">
            {block name='page_content'}
              {block name='product_cover_thumbnails'}
                {include file='../front/_partials/product-cover-thumbnails.tpl'}
              {/block}
              <div class="scroll-box-arrows">
                <i class="material-icons left">&#xE314;</i>
                <i class="material-icons right">&#xE315;</i>
              </div>
            {/block}
          </section>
        {/block}

        </div>
        <div class="col-md-6">
          {block name='page_header_container'}
            {block name='page_header'}
              <h1 class="h1">{block name='page_title'}{$product->name}{/block}</h1>
            {/block}
          {/block}



{if $product->show_price}
  <div class="product-prices js-product-prices">
    
    {block name='product_price'}
      <div
        class="product-price h5 {if $product->on_sale}has-discount{/if}">

        <div class="current-price">
          <span class='current-price-value' content="{$product->price}">
            {capture name='custom_price'}{hook h='displayProductPriceBlock' product=$product type='custom_price' hook_origin='product_sheet'}{/capture}
            {if '' !== $smarty.capture.custom_price}
              {$smarty.capture.custom_price nofilter}
            {else}
              {$product->price}
            {/if}
          </span>
        </div>

      </div>
    {/block}



    {hook h='displayProductPriceBlock' product=$product type="weight" hook_origin='product_sheet'}

    <div class="tax-shipping-delivery-label">
   
      {hook h='displayProductPriceBlock' product=$product type="price"}
      {hook h='displayProductPriceBlock' product=$product type="after_price"}
      
    </div>
  </div>
{/if}





          <div class="product-information">
            {block name='product_description_short'}
              <div id="product-description-short-{$product->id}" class="product-description">{$product->description_short nofilter}</div>
            {/block}

           

            <div class="product-actions js-product-actions">
              {block name='product_buy'}
                <form action="{$urls.pages.cart}" method="post" id="add-to-cart-or-refresh">
                  <input type="hidden" name="token" value="{$static_token}">
                  <input type="hidden" name="id_product" value="{$product->id}" id="product_page_product_id">

                  

                  {block name='product_add_to_cart'}
                    {include file='../front/_partials/product-add-to-cart.tpl'}
                  {/block} 

                  {* {block name='product_additional_info'}
                    {include file='catalog/_partials/product-additional-info.tpl'}
                  {/block} *}

                  {* Input to refresh product HTML removed, block kept for compatibility with themes *}
                  {block name='product_refresh'}{/block} 
                </form>
              {/block}
            </div>

            {block name='hook_display_reassurance'}
              {hook h='displayReassurance'}
            {/block}

            {block name='product_tabs'}
              <div class="tabs">
                <ul class="nav nav-tabs" role="tablist">
                  {if $product->description}
                    <li class="nav-item">
                       <a
                         class="nav-link{if $product->description} active js-product-nav-active{/if}"
                         data-toggle="tab"
                         href="#description"
                         role="tab"
                         aria-controls="description"
                         {if $product->description} aria-selected="true"{/if}>{l s='Description' d='Shop.Theme.Catalog'}</a>
                    </li>
                  {/if}
                  <li class="nav-item">
                    <a
                      class="nav-link{if !$product->description} active js-product-nav-active{/if}"
                      data-toggle="tab"
                      href="#product-details"
                      role="tab"
                      aria-controls="product-details"
                      {if !$product->description} aria-selected="true"{/if}>{l s='Product Details' d='Shop.Theme.Catalog'}</a>
                  </li>
                  {if $attachments}
                    <li class="nav-item">
                      <a
                        class="nav-link"
                        data-toggle="tab"
                        href="#attachments"
                        role="tab"
                        aria-controls="attachments">{l s='Attachments' d='Shop.Theme.Catalog'}</a>
                    </li>
                  {/if}
                </ul>

                <div class="tab-content" id="tab-content">
                 <div class="tab-pane fade in{if $product->description} active js-product-tab-active{/if}" id="description" role="tabpanel">
                   {block name='product_description'}
                     <div class="product-description">{$product->description nofilter}</div>
                   {/block}
                 </div>
<div class="js-product-details tab-pane fade{if !$product->description} in active{/if}"
     id="product-details"
     role="tabpanel"
  >

   {if $features}
      <section class="product-features">
        <p class="h6">{l s='Data sheet' d='Shop.Theme.Catalog'}</p>
        <dl class="data-sheet">
           {foreach from=$features item=feature}
            <dt class="name">{$feature['name']}</dt>
            <dd class="value">{$feature['value']|escape:'htmlall'|nl2br nofilter}</dd>
          {/foreach}
        </dl>
      </section>
    {/if}
  </div>


                 {block name='product_attachments'}
                   {if $attachments}
                    <div class="tab-pane fade in" id="attachments" role="tabpanel">
                       <section class="product-attachments">
                         <p class="h5 text-uppercase">{l s='Download' d='Shop.Theme.Actions'}</p>
                         {foreach from=$attachments item=attachment}
                            <div class="attachment">
                                <h4><a href="{url entity='attachment' params=['id_attachment' => $attachment.id_attachment]}">{$attachment.name}</a></h4>
                                <p>{$attachment.description}</p>
                                <a href="{url entity='attachment' params=['id_attachment' => $attachment.id_attachment]}">
                                    {$attachment.file_name}
                                </a>
                            </div>
                         {/foreach}
                       </section>
                     </div>
                   {/if}
                 {/block}


              </div>
            </div>
          {/block}
        </div>
      </div>
    </div>

     {block name='product_images_modal'}
      {include file='../front/_partials/product-images-modal.tpl'}
    {/block} 

    <div class="alert alert-primary" role="alert">
  A simple primary alert—check it out!
</div>

    

    {* {block name='page_footer_container'}
      <footer class="page-footer">
        {block name='page_footer'}
          <!-- Footer content -->
        {/block}
      </footer>
    {/block} *}
  </section>

{/block}

 

×
×
  • Create New...