Please help us to make AbanteCart Ideal Open Source Ecommerce Solution for everyone.

Support AbanteCart eCommerce

Author Topic: How to correctly add hook to $this->getHookVar('product_description_array')  (Read 7355 times)

Offline yonghan79

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +22/-0
    • View Profile
Hi core devs,

I'm found this hook "$this->getHookVar('product_description_array')" in the product.tpl file.

I have tried to add array like this:

Code: [Select]
$tabs['Test'] = [
       'title' => $view->fetch('pages/test/test_tab.tpl'),
       'html' => $view->fetch('pages/test/test_content.tpl')
];
$that->view->addHookVar('product_description_array',$tabs);

It's not working.

I tried to debug in the tpl file and found out that the variable is set as a string contains 'array', not a real array.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2091
  • Karma: +331/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
hook var's value must be a string, not array.
Different extensions can add it's values and we use concatenation for that
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline yonghan79

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +22/-0
    • View Profile
This is what is in products.tpl file:

Code: [Select]
$hookVarArray = $this->getHookVar('product_description_array');
                if( $hookVarArray ){
                foreach($hookVarArray as $key=>$hkVar){ ?>
                <div class="accordion-item">
                    <h2 class="accordion-header" id="heading<?php echo $key?>>">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse<?php echo $key?>"
                                aria-expanded="true" aria-controls="collapse<?php echo $key?>">
                            <?php echo $hkVar['title']; ?>
                        </button>
                    </h2>
                    <div id="collapse<?php echo $key?>" class="accordion-collapse collapse" aria-labelledby="heading<?php echo $key?>" data-bs-parent="#productDetailsAccordion">
                        <div class="accordion-body">
                            <?php echo $hkVar['html']; ?>
                        </div>
                    </div>
                </div>

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2091
  • Karma: +331/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
$hookVarArray is a string, not array!
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2091
  • Karma: +331/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
if you want to pass an array use $that->view->assign('your_tpl_variable_name', $someArray); inside your hook file where $that = $this->baseObject; (controller instance)
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

 

Powered by SMFPacks Social Login Mod