I have an issue which is loader still loading in product detail page when i migrate magento 2.4.0 to magento 2.4.1
am expecting to load product detail page properly
issue is not coming display none or hide in loader div
<div class="gallery-placeholder _block-content-loading" data-gallery-role="gallery-placeholder">
<div data-role="loader" class="loading-mask">
<div class="loader">
<img src="<?php /* #escapeNotVerified */ echo $block->getViewFileUrl('images/loader-1.gif'); ?>"
alt="<?php /* #escapeNotVerified */ echo __('Loading...') ?>">
</div>
</div>
</div>
<!--Fix for jumping content. Loader must be the same size as gallery.-->
<script>
var config = {
"width": <?php /* #escapeNotVerified */ echo $width; ?>,
"thumbheight": <?php /* #escapeNotVerified */ echo $thumbHeight ?: $thumbWidth; ?>,
"navtype": "<?php /* #escapeNotVerified */ echo $block->getVar("gallery/navtype"); ?>",
"height": <?php /* #escapeNotVerified */ echo $height; ?>
},
thumbBarHeight = 0,
loader = document.querySelectorAll('[data-gallery-role="gallery-placeholder"] [data-role="loader"]')[0];
if (config.navtype === 'horizontal') {
thumbBarHeight = config.thumbheight;
}
loader.style.paddingBottom = ( config.height / config.width * 100) + "%";
</script>
Related
Actually I am working on front-end, but I cannot reach the backend developer and I need to fix a bug.
The problem is exactly this, if there is no image in a content, we get an error like this:
A PHP Error was encountered
A
Severity: Notice
Message: Undefined property: stdClass:$Pictures
Filename:agent/hotel_detail.php
Line Number: 17
Backtrace:
File:/home/tungatour/public_html/application/views/agent/hotel_detail.php
Line: 17
Function: _error_handler
File:/home/tungatour/public_html/application/controllers/Agent.php
Line: 490
Function: view
File:/home/tungatour/public_htm/index.php
I just want to show demo image instead if there is no image. But i dont have any idea how can i do this ?
so i have controller codes about picture this this.
public function post($ID)
{
$viewData["title"] = "Post Details";
$data = $this->db->where("ID", $ID)->get("post")->row();
$data->Meta = json_decode($data->Meta);
$picture = $this->db->where("ID", $data->Meta->Thumbnail)->get("picture")->row();
$viewData["data"] = $data;
$viewData["picture"] = $picture;
$this->load->view('partials/agent/head', $viewData);
$this->load->view('agent/post', $viewData);
$this->load->view('partials/agent/foot', $viewData);
}
also i have this lines` <?php $first = true;
for ($i = 0; $i < $this->db->where_in("ID", $data->Meta->Pictures)->count_all_results("picture"); $i++) { ?>
<li data-target="#carousel-example-generic" data-slide-to="<?= $i ?>" class="<?= $first ? "active" : "" ?>"></li>
<?php $first = false;
} ?>
</ol>
<div class="carousel-inner" role="listbox">
<?php $first = true;
foreach ($this->db->where_in("ID", $data->Meta->Pictures)->get("picture")->result() as $picture) { ?>
<div class="carousel-item <?= $first ? "active" : "" ?>">
<img class="img-fluid" src="<?= $picture->URL ?>" style="height: 420px;width: 100%;object-fit: cover;" />
</div>
<?php $first = false;
} ?>
</div>`
Change this line
<img class="img-fluid" src="<?= $picture->URL ?>" style="height: 420px;width: 100%;object-fit: cover;" />
Update with
<?php if($picture->URL) { ?>
<img class="img-fluid" src="<?= $picture->URL ?>" style="height: 420px;width: 100%;object-fit: cover;" />
<?php } ?>
If the image has a URL, it will display the image. Otherwise it will be empty.
I am using opencart version 2.0.2.0 and now i am trying to get image or image url in manufacturer page.
I have added the code in catalog/controller/product/manufacturer.php
$manufacturer_image = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
if($manufacturer_image){
$this->data['manufacturers_img'] = $this->model_tool_image->resize($manufacturer_image['image'], 120, 120);
}else{
$this->data['manufacturers_img'] = false;
}
and call it in catalog/view/theme/default/template/product/manufacturer_list.tpl
<div class="row">
<?php foreach ($manufacturers as $manufacturer) { ?>
<div class="col-sm-3"><?php echo $manufacturer['name']; ?>
<?php echo ($manufacturers_img) ? '<img src="'.$manufacturers_img.'" alt="'.$manufacturers.'" />' : $manufacturers ;?><br />
</div>
<?php } ?>
</div>
But it's getting error in my /index.php?route=product/manufacturer page
Notice: Undefined variable: manufacturers_img in
/data1/opencart-2.0.2.0/catalog/view/theme/default/template/product/manufacturer_list.tpl
on line 32Array
lets be clear ControllerProductManufacturer index() shows list and info() shows detail of the mfg,
//catalog/controller/product/manufacturer.php:46
Replace
$data['categories'][$key]['manufacturer'][] = array(
with
$manufacturer_image = $this->model_catalog_manufacturer->getManufacturer($result['manufacturer_id']);
if($manufacturer_image){
$mfg_img = $this->model_tool_image->resize($manufacturer_image['image'], 120, 120);
}else{
$mfg_img = false;
}
$data['categories'][$key]['manufacturer'][] = array(
'image'=>$mfg_img,
And in catalog/view/theme/default/template/product/manufacturer_list.tpl:30
inside loop
<?php if($manufacturer['image']):?>
<img src="<?php echo $manufacturer['image']; ?>" alt="<?php echo $manufacturer['name'];?>">
<?php endif;?>
I'm using magento and I have a new product slider on my homepage that shows the new products but it is only one row big and I want to decide if it's 2 rows or more on my homepage but i don't know what i need to change in the .phtml file so it is 2 rows instead of one.
If you go to parts2u.nl you can see what i mean underneath Nieuwe Artikelen that is the new product slider I'm talking about.
This is the code:
<?php
/**
*
*/
?>
<?php
$_productCollection = $this->getProductCollection();
?>
<?php if ($_productCollection && ($_collectionSize = $_productCollection->getSize())): ?>
<?php
$theme = $this->helper('fortis');
$helpLabels = $this->helper('fortis/labels');
$helpTemplate = $this->helper('fortis/template');
$helpImg = $this->helper('infortis/image');
$sliderClasses = '';
$gridClasses = '';
//Default image size
$imgWidth = 168;
$imgHeight = 168;
//Image aspect ratio
if ($theme->getCfg('category/aspect_ratio'))
{
$imgHeight = 0; //Height will be computed automatically (based on width) to keep the aspect ratio
}
//Basic slider block parameters
//--------------------------------------------------------------
$isResponsive = $this->getIsResponsive(); //param: is_responsive
$breakpoints = $this->getBreakpoints(); //param: breakpoints
$showItems = $this->getShowItems(); //param: show_products
if (!$showItems)
{
$showItems = 5; //IMPORTANT: set default number of visible products
}
//Slider timeout (if set: automatic slideshow)
$timeout = $this->getTimeout(); //param: timeout
if ($timeout === NULL) //Param not set
{
$timeout = intval($theme->getCfg('product_slider/timeout'));
}
else
{
$timeout = intval($timeout);
}
//Slider initial delay
$initDelay = intval($this->getInitDelay()); //param: init_delay
//Number of items that should move on animation
$move = $this->getMove(); //param: move
if ($move === NULL) //Param not set
{
$move = intval($theme->getCfg('product_slider/move_items'));
}
else
{
$move = intval($move);
}
//Additional slider classes
//--------------------------------------------------------------
if($isResponsive)
{
$sliderClasses .= ' itemslider-responsive';
}
if ($_collectionSize == 1)
{
$sliderClasses .= ' single-item';
}
//Additional grid classes
//--------------------------------------------------------------
//Size of grid elements
$size = $this->getSize(); //param: size
if ($size)
{
$gridClasses = ' ' . $size;
}
else
{
if ($showItems >= 8)
{
$gridClasses = ' size-xs';
}
elseif ($showItems >= 6)
{
$gridClasses = ' size-s';
}
}
//Align elements to the center
if ($this->getCentered()) //param: centered
{
$gridClasses .= ' centered';
}
//Set equal height for all items
if ($this->getEqualHeight()) //param: equal_height
{
$gridClasses .= ' equal-height';
}
?>
<h3 class="section-title padding-right"><?php echo $this->getBlockName(); ?></h3>
<div class="itemslider-wrapper new-itemslider-wrapper">
<div class="nav-wrapper gen-slider-arrows1 gen-slider-arrows1-pos-top-right"></div>
<div class="itemslider itemslider-horizontal<?php if($sliderClasses) echo $sliderClasses; ?>">
<ul class="slides products-grid<?php if($gridClasses) echo $gridClasses; ?>">
<?php foreach ($_productCollection->getItems() as $_product): ?>
<li class="item">
<div class="product-image-wrapper" style="max-width:<?php echo $imgWidth; ?>px;">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true); ?>" class="product-image">
<img src="<?php echo $helpImg->getImg($_product, $imgWidth, $imgHeight, 'small_image'); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true); ?>" />
<?php if ($theme->getCfg('category/alt_image')): ?>
<?php echo $theme->getAltImgHtml($_product, $imgWidth, $imgHeight); ?>
<?php endif; ?>
<?php echo $helpLabels->getLabels($_product); //Product labels ?>
</a>
<?php //Add-to links
if ($theme->getCfg('category_grid/display_addtolinks') != 0
&& $theme->getCfg('category_grid/addtolinks_simple'))
{
if ($theme->getCfg('category_grid/display_addtolinks') == 1) //Display on hover
{
echo $helpTemplate->getCategoryAddtoLinksComplex_2(
$_product, $this->getAddToCompareUrl($_product), 'addto-links-icons addto-onimage visible-onhover');
}
else //Always display
{
echo $helpTemplate->getCategoryAddtoLinksComplex_2(
$_product, $this->getAddToCompareUrl($_product), 'addto-links-icons addto-onimage');
}
}
?>
</div> <!-- end: product-image-wrapper -->
<h3 class="product-name"><?php echo $this->escapeHtml($_product->getName()) ?></h3>
<?php echo $this->htmlEscape($_product->getSku()); ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php echo $this->getPriceHtml($_product, true, '-new') ?>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<?php if ($this->getHideButton() == false): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php endif; ?>
<?php else: ?>
<?php if ($this->getHideButton() == false): ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php endif; ?>
<?php //Add-to links
if ($theme->getCfg('category_grid/display_addtolinks') != 0 && !$theme->getCfg('category_grid/addtolinks_simple'))
{
if ($theme->getCfg('category_grid/display_addtolinks') == 1) //Display on hover
echo $helpTemplate->getCategoryAddtoLinks($_product, $this->getAddToCompareUrl($_product), 'addto-gaps-right addto-texticons display-onhover');
else //Always display
echo $helpTemplate->getCategoryAddtoLinks($_product, $this->getAddToCompareUrl($_product), 'addto-gaps-right addto-texticons');
}
?>
</div>
</li>
<?php endforeach; ?>
</ul> <!-- end: slides -->
</div> <!-- end: itemslider -->
</div> <!-- end: new-itemslider-wrapper -->
<script type="text/javascript">
//<![CDATA[
jQuery(function($) {
$('.new-itemslider-wrapper .itemslider').flexslider({
namespace: "",
animation: "slide",
easing: "easeInQuart",
<?php if ($timeout): ?>
slideshowSpeed: <?php echo $timeout; ?>,
animationLoop: true,
<?php else: ?>
slideshow: false,
animationLoop: false,
<?php endif; ?>
<?php if ($initDelay): ?>
initDelay: <?php echo $initDelay; ?>,
<?php endif; ?>
<?php if ($speed = intval($theme->getCfg('product_slider/speed'))): ?>
animationSpeed: <?php echo $speed; ?>,
<?php endif; ?>
pauseOnHover: true,
controlNav: false,
controlsContainer: ".new-itemslider-wrapper .nav-wrapper",
itemWidth: 188,
<?php if ($showItems): ?>
minItems: <?php echo $showItems; ?>,
maxItems: <?php echo $showItems; ?>,
<?php endif; ?>
move: <?php echo $move; ?>
})
<?php if ($breakpoints): ?>
.data("breakpoints", [ <?php echo $breakpoints; ?> ] )
<?php elseif ($showItems): ?>
.data("showItems", <?php echo $showItems; ?> )
<?php endif; ?>
; //IMPORTANT: don't remove semicolon!
});
//]]>
</script>
<?php endif; ?>
This seems like an incredibly convoluted implementation. I recommend that you seriously invest some time building your own slider rather than attempting to hack this to work the way you desire. Super cereal.
I have a shop with configurable Products.
In the category page with all my products, I want to add text before the price.
How can I do that? I use the Modern theme.
add your text before getPriceHtml($_product, true) ?> in catalog/product/list.phtm
Something like following :
<?php echo "YOUR TEXT" ?>
<?php echo $this->getPriceHtml($_product, true) ?>
you can look in
app/design/frontend/default/yourtheme/template/catalog/product/price.phtml
if your theme in have no file use
you can look in
\app\design\frontend\base\default\template\catalog\product\price.phtml
Around line 189 you will find the following:
<span id=”product-price-<?php echo $_id ?>
<?php echo $this->getIdSuffix() ?>”>
Just add the following above the line:
<?php echo $this->__(‘Your Text Goes Here:’) ?>
so that you have something like this:
<?php echo $this->__(‘Your Text Goes Here:’) ?>
<span class=”regular-price” id=”product-price-<?php echo $_id ?>
<?php echo $this->getIdSuffix() ?>”>
Your text will be reflected before the price in both
the catalog and the product page.
In magento 2, You need to make changes in price-box.js which is placed at
/vendor/magento/module-catalog/view/base/web/js/price-box.js
Make sure you take this js in your custom theme folder and make changes on line number 22 near
priceTemplate: '<span class="price"><%- data.formatted %></span>'
Add your custom text after <span class="price">
Some thing like this,
priceTemplate: '<span class="price">Price - <%- data.formatted %></span>'
Done.
For adding label before price you need to override final_price.phtml file in your custom theme -
Core file path -
vendor/magento/module-catalog/view/base/templates/product/price/final_price.phtml
Override in your custom theme -
app/design/frontend/VendorName/ThemeName/Magento_Catalog/templates/product/price/final_price.phtml
Change code as below -
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// #codingStandardsIgnoreFile
?>
<?php
/** #var \Magento\Catalog\Pricing\Render\FinalPriceBox $block */
/** ex: \Magento\Catalog\Pricing\Price\RegularPrice */
/** #var \Magento\Framework\Pricing\Price\PriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');
/** ex: \Magento\Catalog\Pricing\Price\FinalPrice */
/** #var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
$schema = ($block->getZone() == 'item_view') ? true : false;
?>
<?php if ($block->hasSpecialPrice()): ?>
<span class="special-price">
<?php /* #escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('Custom Label 1 : '),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]); ?>
</span>
<span class="old-price">
<?php /* #escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
'display_label' => __('Custom Label 2 : '),
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
'price_type' => 'oldPrice',
'include_container' => true,
'skip_adjustments' => true
]); ?>
</span>
<?php else: ?>
<?php /* #escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('Custom Label 3 : '),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]); ?>
<?php endif; ?>
<?php if ($block->showMinimalPrice()): ?>
<?php if ($block->getUseLinkForAsLowAs()):?>
<a href="<?= /* #escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
<?= /* #escapeNotVerified */ $block->renderAmountMinimal() ?>
</a>
<?php else:?>
<span class="minimal-price-link">
<?= /* #escapeNotVerified */ $block->renderAmountMinimal() ?>
</span>
<?php endif?>
<?php endif; ?>
Here I have change text in below code also added in this code in last else condition as it was not present in else condition.
'display_label' => __('Custom Label 3 : '),
Thanks
I am Facing one problem when i want to display recent products for guest user, is there any ways to show recently view product for guest user,
Magento support Recently View Product For Registered User But for Guest User How to show Recently view products by that particular Guest...
I am waiting for your kind response,
Hope i get some reply on this.
Thanks in advance.
here is phtml
<?php if ($_products = $this->getRecentlyViewedProducts()):
$ids = '';
foreach ($_products as $_item) {
$ids .= $_item->getId() . ';';
}
?>
<div class="lftHeading">
<span
style="text-transform:capitalize;background:url(<?php echo $this->getSkinUrl('css/images/clo_left_heading_bullet2.gif') ?>) top left no-repeat;"
>recently viewed</span>
</div>
<div class="innerRgtMenu recently_viewed_block">
<table id="recently-viewed-items">
<?php $i = 0; foreach ($_products as $_item): if ($i == 3) {
continue;
} ?>
<?php $product = $_item ?>
<tr>
<td><a style="border:1px solid #DDDDDD;float:left;margin:5px;padding:5px;"
href="<?php echo $this->getProductUrl($_item, array('_nosid' => true)) ?>" class="product-image"><img
src="<?php echo $this->helper('catalog/image')->init($product, 'thumbnail')->resize(50) ?>"
width="50" alt="<?php echo $this->escapeHtml($_item->getName()) ?>"/></a></td>
<td><a style="position:relative;top:3px;font-size:11px;"
href="<?php echo $this->getProductUrl($_item, array('_nosid' => true)) ?>"><?php echo $this->escapeHtml($_item->getName()) ?></a>
</td>
</tr>
<?php $i++;
endforeach; ?>
</table>
<div style="margin: 5px 0px 5px 2px; text-align: center; width: 140px;">
<input type="button" class="button recently_viewed_btn" value="<?php echo $this->__('Email These To Me') ?> "
onClick="email_recently('<?php echo $ids; ?>')"/>
</div>
<div style="margin:5px;">
<?php echo $this->__('See All Recently Viewed') ?>
</div>
<script type="text/javascript">decorateList('recently-viewed-items');</script>
and php file
class Mage_Reports_Block_Product_Viewed extends Mage_Reports_Block_Product_Abstract
{
const XML_PATH_RECENTLY_VIEWED_COUNT = 'catalog/recently_products/viewed_count';
/**
* Viewed Product Index model name
*
* #var string
*/
protected $_indexName = 'reports/product_index_viewed';
/**
* Retrieve page size (count)
*
* #return int
*/
public function getPageSize()
{
if ($this->hasData('page_size')) {
return $this->getData('page_size');
}
return Mage::getStoreConfig(self::XML_PATH_RECENTLY_VIEWED_COUNT);
}
/**
* Added predefined ids support
*/
public function getCount()
{
$ids = $this->getProductIds();
if (!empty($ids)) {
return count($ids);
}
return parent::getCount();
}
/**
* Prepare to html
* check has viewed products
*
* #return string
*/
protected function _toHtml()
{
if (!$this->getCount()) {
return '';
}
$this->setRecentlyViewedProducts($this->getItemsCollection());
return parent::_toHtml();
}
}
if it will not work for guests - try to change last function in php file to
protected function _toHtml()
{
/* if ($this->_hasViewedProductsBefore() === false) {
return '';
} */
$this->setDisplayMinimalPrice('1');
$collection = $this->_getRecentProductsCollection();
$hasProducts = (bool)count($collection);
// if (is_null($this->_hasViewedProductsBefore())) {
// Mage::getSingleton('reports/session')->setData('viewed_products', $hasProducts);
// }
if ($hasProducts) {
$this->setRecentlyViewedProducts($collection);
}
return parent::_toHtml();
}
Block Recently Viewed Products works fine without any code modification in magento 1.6-1.9.2.2
If block is not shown you need check:
Block is properly added to page in visible container (by default block added to right sidebar)
Log is Enabled. Check System->Configuration->System->Log Option "Enable Log" = Yes
Rebuild index "Category Product" (catalog_category_product)
as far as I know - it should work fine for guests. at least it works on my site
here is how I put that on a page:
<block type="reports/product_viewed" name="reports.product.recently.viewed" template="reports/recently_viewed.phtml" />