News:

Support the VirtueMart project and become a member

Main Menu

[SOLVED] Admin template override & ACL & image display problem

Started by dnlvsci, February 27, 2019, 17:45:56 PM

Previous topic - Next topic

dnlvsci

Joomla version: 3.9.2 VM vers. virtuemart.3.4.3.10014 / virtuemart.3.4.3.10020

I made admin template override, where order page show product image too. When i'm super user, image showed, but when i'm manager image is missing. On ACL setup product edit,create,delete, acces is enabled, media handling too, order handling (all possibilites) too. Manager cant acces to product model fully. Example product pranet id is 0 however product has parent id. Why this necessary? Because child product hasn't image, so i acces image via parent.... If get product parent ID via product model function, image is empty too.

My code:
Case 1 (manager get 0 for product_parent_id):

            <?php
               $product_id = $item->virtuemart_product_id;
               
               if(isset($item->product_parent_id) && $item->product_parent_id != 0) {
                  $product_id = $item->product_parent_id;
               }
            
               $productModel = VmModel::getModel('product');
               $product = $productModel->getProduct($product_id);
               $productModel->addImages($product,1);
               
               if(isset($product->images[0])) {
                  //echo $product->images[0]->displayMediaThumb("",true,"rel='vm-additional-images' style='max-width:80px;'");
                  echo '<img src="'.juri::root().$product->images[0]->getFileUrlThumb().'" style="max-width:70px;"/>';
               }
               ?>

Case 2 (force getting parent_id, Image still empty)

            <?php

               $product_id = $item->virtuemart_product_id;
               $productModel = VmModel::getModel('product');
               $parent = $productModel->getProductParentId($product_id);

               if(isset($item->product_parent_id) && $parent != 0) {
                  $product_id = $parent;
               }
            
               
               $product = $productModel->getProduct($product_id);
               $productModel->addImages($product,1);
               
               if(isset($product->images[0])) {
                  //echo $product->images[0]->displayMediaThumb("",true,"rel='vm-additional-images' style='max-width:80px;'");
                  echo '<img src="'.juri::root().$product->images[0]->getFileUrlThumb().'" style="max-width:70px;"/>';
               }
               ?>

Any idea what I'm missing?

Thanks



dnlvsci

#1
I solved my self. Not an ACL issue....

If need for somebody:

you must add "false" (means call not from frontend) to $productModel->getProduct so right code is:

$productModel->getProduct($product_id,false);