this code out put is here....(look at the footer subscribe section )
<?php if(!empty($this->items))foreach($this->items as $level): ?>
<?php
$formatedPrice = sprintf('%1.02f',$level->price);
$dotpos = strpos($formatedPrice, '.');
$price_integer = substr($formatedPrice,0,$dotpos);
$price_fractional = substr($formatedPrice,$dotpos+1);
?>
<div class="level akeebasubs-level-<?php echo $level->akeebasubs_level_id ?>">
<p class="level-title">
<span class="level-price">
<?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'before'): ?>
<span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
<?php endif; ?>
<span class="level-price-integer"><?php echo $price_integer ?></span><?php if((int)$price_fractional > 0): ?><span class="level-price-separator">.</span><span class="level-price-decimal"><?php echo $price_fractional ?></span><?php endif; ?>
<?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'after'): ?>
<span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
<?php endif; ?>
</span>
<span class="level-title-text">
<a href="<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>">
<?php echo $this->escape($level->title)?>
</a>
</span>
</p>
<div class="level-inner">
<div class="level-description">
<div class="level-description-inner">
<?php if(!empty($level->image)):?>
<img class="level-image" src="<?php echo JURI::base()?><?php echo trim(AkeebasubsHelperCparams::getParam('imagedir','images/'),'/') ?>/<?php echo $level->image?>" />
<?php endif;?>
<?php echo JHTML::_('content.prepare', AkeebasubsHelperMessage::processLanguage($level->description));?>
</div>
</div>
<div class="level-clear"></div>
<div >
<button onclick="window.location='<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>'">
<?php echo JText::_('COM_AKEEBASUBS_LEVELS_SUBSCRIBE')?>
</button>
</div>
</div>
</div>
<?php endforeach; ?>
this is the language file contain that name
COM_AKEEBASUBS_LEVELS_SUBSCRIBE="Subscribe Now"
I want to name those three sections butons as 6month,12month,24month
How will change the code ?
If you are unable to get the value using PHP, try changing the value of the button's name on page load
Here is the JQUERY
$(document).ready(function){
$('div.akeebasubs-awesome-description').each(function(
substription = $(this).children('H4').html()
button = $(this).parent().next().children('button')
$(button).attr(name,substription.split(' ')[0]+'month')
})
})
and the JAVASCRIPT
divs = document.getElementsByClassName('akeebasubs-awesome-description');
for (var i in divs){
divs[i].parentElement.nextElementSibling.children[0].name = divs[i].children[0].innerHTML.split(' ')[0] + 'month'
}
This will take the text of the H4 and make that the corresponding button's name
Related
I have a block being displayed on my homepage which shows a product, whose id we specify. The code on homepage (static block) looks like this:
{{block type="core/template" product_id="2559" template="catalog/product/one_product.phtml"}}
The one_product.phtml file contains this code:
<?php
$productId = $this->getProduct_id();
$product = Mage::getModel('catalog/product')->load($productId); //load product
?>
<div class="product">
<a href="<?php echo $product->getProductUrl() ?>" >
<img class="product-img" src="<?php echo $this->helper('catalog/image')->init($product, 'image'); ?>"alt="<?php echo $this->htmlEscape($product->getName()) ?>" />
</a>
</div>
<div class="product-detail">
<P><?php // echo $this->htmlEscape($product->getName()) ?>
<?php $prod_name = $this->htmlEscape($product->getName()); ?>
<?php
$count_str = strlen($prod_name);
if ($count_str < 40) {
echo $prod_name;
} else {
$offset = 0;
$length = 41;
$prod_name = html_entity_decode($prod_name);
echo htmlentities(mb_substr($prod_name,0,$length,'utf-8')). "...";;
}
?>
</P>
<!--?php $price = $product->getPrice() ; ?-->
<?php $_product = Mage::getModel('catalog/product')->load($product->getId());
$productBlock = $this->getLayout()->createBlock('catalog/product_price');
?>
<span>
<?php echo $productBlock->getPriceHtml($_product); ?>
<?php $tier_price = end($_product->getTierPrice());
if($tier_price !='0'){ ?>
<span>As Low As:</span>
<?php
echo " ₹ ".number_format( $tier_price['price']);
} ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart"
onclick="setLocation('<?php echo Mage::helper('checkout/cart')->getAddUrl($product); ?>')">
</span>
</div>
So basically I want to show random products out of the ones I specify separated by commas. For eg: I specify in the static block product_id="2559,2661,2857,9293" and it should show any one of those 4 products randomly.
What is the way to do that?
Also any way to make it pull products from SKU also? Since we remember all the SKUs but we have to check each product ID everytime we change the product here.
Please excuse me if the question is too basic, I'm not a developer.
You can see it in action at www.giftzila.com
Thanks!
Create a new file called random-product.phtml at app/design/frontend/default/Your_Theme/template/catalog/random-product.phtml then add the following code in that file
<?php
$chosen_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$_productCollection = $this->getLoadedProductCollection();
$number_of_products = $this->getNumProducts();
if (sizeof($_productCollection) < $number_of_products) {
$number_of_products = sizeof($_productCollection);
}
$displayed_products = array();
foreach ($_productCollection as $_product) {
$displayed_products[] = $_product;
}
$random_products = array();
if (sizeof($_productCollection) > 1) {
$random_products = array_rand($displayed_products, $number_of_products);
} else {
$random_products = array('0');
}
?>
<?php if(!$_productCollection->getSize()):?>
<div class="note-msg">
<?=$this->__('There are no products matching the selection.')?>
</div>
<?php else:?>
<div class="main-binder">
<div class="cms-box">
<div class="category-title">
<h2>Random Products</h2>
</div>
<div class="category-products">
<table id="products-grid-table" class="products-grid">
<?php
$k=0;
for ($i=0; $i < $number_of_products; $i++): ?>
<?php if ($k == 0) { ?>
<tr class="first odd">
<?php } if($k==3) { $k=0; ?>
</tr><tr class="first odd even">
<?php } ?>
<td id="td_<?php echo ($k+1); ?>" <?php if($k==3){ ?>class="last"<? } ?> >
<div class="cms-box">
<div id="cont_<?php echo ($k+1); ?>">
<div class="product-name-block">
<?php
$pname=$this->htmlEscape($displayed_products[$random_products[$i]]->getName());
?>
<h3 class="product-name">
<a href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>" title="<?php echo $pname; ?>">
<?php if(strlen($pname) > 28) {echo substr($pname,0,25)."...";}else {echo $pname;}?>
</a></h3>
</div>
<div class="image-box">
<a class="product-image" href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>"> <img src="<?php echo $this->helper('catalog/image')->init($displayed_products[$random_products[$i]], 'small_image')->resize(140);?>" alt="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>" title="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>"/> </a>
</div>
<div class="cms-price-box" style=" text-align:center;">
<span class="regular-price" id="product-price-37">
<span class="price" ><?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol().$displayed_products[$random_products[$i]]->getPrice(); ?></span>
</span>
</div>
<div class="button-row" style="text-align:center;">
<button onclick="setLocation('<?php echo $displayed_products[$random_products[$i]]->getProductUrl();?>')" class="button" type="button"><span><span><span>Details</span></span></span></button>
<button onclick="setLocation('<?php echo $this->getUrl('')."/checkout/cart/add?product=".$displayed_products[$random_products[$i]]->getId()."&qty=1" ?>')" class="button"><span><?php echo $this->__('Add to Cart') ?></span></button>
</div>
</div>
</div></td>
<?php $k++; ?>
<?php endfor;?>
</tr>
</table>
</div>
</div>
</div>
<?php endif;?>
Now call block in your cms home page by adding following code:-
{{block type="catalog/product_list" category_id="3" num_products="8" template="catalog/random-product.phtml"}}
I'm working with Magento EE v1.14 and i'm looking for a solution for when a user is viewing a product page to then drop swatches of related product colors if they are out of stock.
Screenshot: Highlighted out of stock related product color
Screenshot of HTML
PHP + HTML code:
<?php
$_base_product = $this->getProduct();
$base_product = Mage::getModel('catalog/product')->load($_base_product->getId());
$base_product_id = $base_product->getId();
$base_name = $base_product->getName();
$base_url = Mage::getBaseUrl();
$product_colors = Mage::getModel('catalog/product')->getCollection();
$product_colors->addAttributeToFilter('status',1); // 1 or 2
$product_colors->addAttributeToFilter('visibility',4); // 1.2.3.4
$product_colors->addAttributeToFilter('name', array('eq' => $base_name));
$product_colors->addAttributeToFilter('sku', array('neq' => $base_product->getSku()));
$product_colors_ids = $product_colors->getAllIds(); // get all products from the category
sort($product_colors_ids);
?>
<?php if(count($product_colors_ids) > 0) : ?>
<div id="product-color-options-wrapper">
<div id="product-color-options-container">
<label><?php echo $this->__('Color') ?> / <span style="font-weight: normal;"><?php echo $base_product->getAttributeText('color'); ?></span></label>
<div id="color-options-wrapper">
<?php $_swatch_img = $base_product->getMediaGalleryImages(false)->getItemByColumnValue('label', 'swatch') ?>
<?php if($_swatch_img) : ?>
<div class="current-product-wash-wrapper wash-wrapper">
<div class="current-product-wash-container wash-container">
<img src="<?php echo $this->helper('catalog/image')->init($base_product, 'small_image', $_swatch_img->getFile())->resize(33,30) ?>" alt="" title="<?php echo $base_product->getAttributeText('color') ?>" />
</div>
</div>
<?php else : ?>
<!-- <span><?php echo $base_product->getColor() ?></span> -->
<?php endif ?>
<?php foreach($product_colors_ids as $prod_id) : ?>
<?php $_sister_product = Mage::getModel('catalog/product')->load($prod_id) ?>
<?php
$_sister_prod_imgs = $_sister_product->getMediaGallery('images');
foreach($_sister_prod_imgs as $_sister_prod_img):
if($_sister_prod_img['label'] == 'swatch'):
$_swatch_img = $_sister_prod_img['file'];
endif;
endforeach;
?>
<?php if($_swatch_img): ?>
<div class="sister-product-wrapper wash-wrapper">
<div class="sister-product-container wash-container">
<a href="<?php echo $base_url ?><?php echo $_sister_product->getUrlKey() ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_sister_product, 'small_image', $_swatch_img)->resize(33,30); ?>" alt="" title="<?php echo $_sister_product->getAttributeText('color') ?>">
</a>
</div>
</div>
<?php endif; ?>
<?php endforeach ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php endif ?>
Any help would be appreciated! :D
**Solution:**Added an if statement to check for stock availability using the isAvailable() function, shown in screenshot.
Link to screenshot: https://gyazo.com/abf07ba0373877836571858ee129cc22
I'm making a php tag script for my website.
I have completed the code, but I'm afraid my code is too long.
Can my code be more simple and short?
<?php
include("admin/apps/site-settings.php"); // database connection
$albumq = mysql_query("select * from albums order by rand() limit 20");
while($album = mysql_fetch_array($albumq)){
$name_a = str_replace("'s","",$album['name']);
$name_b = str_replace(""","",$name_a);
$name_c = str_word_count($name_b, 1);
?>
<?php if(!empty($name_c[0])){?>
<a href="search-<?php echo $name_c[0];?>.html">
<div class="tag">
<?php echo $name_c[0];?>
</div>
</a>
<?php }?>
<?php if(!empty($name_c[1])){?>
<a href="search-<?php echo $name_c[1];?>.html">
<div class="tag">
<?php echo $name_c[1];?>
</div>
</a>
<?php }?>
<?php if(!empty($name_c[2])){?>
<a href="search-<?php echo $name_c[2];?>.html">
<div class="tag">
<?php echo $name_c[2];?>
</div>
</a>
<?php }?>
<?php if(!empty($name_c[3])){?>
<a href="search-<?php echo $name_c[3];?>.html">
<div class="tag">
<?php echo $name_c[3];?>
</div>
</a>
<?php }?>
<?php if(!empty($name_c[4])){?>
<a href="search-<?php echo $name_c[4];?>.html">
<div class="tag">
<?php echo $name_c[4];?>
</div>
</a>
<?php }?>
<?php if(!empty($name_c[5])){?>
<a href="search-<?php echo $name_c[5];?>.html">
<div class="tag">
<?php echo $name_c[5];?>
</div>
</a>
<?php }?>
Output in the website:
I'm running it on localhost so I can't provide a link at the moment.
<?php
include("admin/apps/site-settings.php"); // database connection
$albumq = mysql_query("select * from albums order by rand() limit 20");
while($album = mysql_fetch_array($albumq)){
$name_a = str_replace("'s","",$album['name']);
$name_b = str_replace(""","",$name_a);
$name_c = str_word_count($name_b, 1);
foreach ($name_c as $value)
{
if (!empty($value))
{
echo "
<a href='search-{$value}.html'>
<div class='tag'>
{$value}
</div>
</a>";
}
}
}
?>
Use foreach loop for same , use like
if(count($name_c) > 0)
{
foreach($name_c as $name)
{
?>
<a href="search-<?php echo $name; ?>.html">
<div class="tag">
<?php echo $name; ?>
</div>
</a>
<?php
}
}
I have a problem looping my html tags. My goal is to enclose every 4 div with class "item" inside the class of "item-wrap". So far here's my code:
$speakers will return 8 rows so "item-wrap" class will be display twice with 4 "item" class inside
<?php
$speaker_ctr = 0;
if(count($speakers) > 0){
?>
<div class="item-wrap">
<?php foreach($speakers as $speaker){ ?>
<div class="item"> <img class="lazy" data-lazy-src="<?php echo $speaker['imagepath']; ?>" />
<h5 class="txt-18 bold-font text-uppercase no-mbt mt-20"><?php echo $speaker['name']; ?></h3>
<p class="no-mn"><?php echo $speaker['position']; ?></p>
<?php echo $speaker['company']; ?>
</div>
<?php } ?>
</div>
<?php
$speaker_ctr++;
}
?>
Try below code:-
<?php
if(count($speakers) > 0){
for($i=0;$i<=count($speakers);$i++){
if($i%4==0){
echo '<div class="item-wrap">';
}
?>
<div class="item"> <img class="lazy" data-lazy-src="<?php echo $speakers[$i]['imagepath']; ?>" />
<h5 class="txt-18 bold-font text-uppercase no-mbt mt-20"><?php echo $speakers[$i]['name']; ?></h3>
<p class="no-mn"><?php echo $speakers[$i]['position']; ?></p>
<?php echo $speakers[$i]['company']; ?>
</div>
<?php
if($i%4==0){
echo '</div>';
}
}
}
Try with -
$speaker_ctr = 0;
if(count($speakers) > 0){
?>
<div class="item-wrap">
<?php
foreach($speakers as $speaker){
$speaker_ctr++; // increment
?>
<div class="item"> <img class="lazy" data-lazy-src="<?php echo $speaker['imagepath']; ?>" />
<h5 class="txt-18 bold-font text-uppercase no-mbt mt-20"><?php echo $speaker['name']; ?></h3>
<p class="no-mn"><?php echo $speaker['position']; ?></p>
<?php echo $speaker['company']; ?>
</div>
<?php
// print if divisible by 4
// every 4th element
if($speaker_ctr%4 == 0 && $speaker_ctr != count($speakers)) {
echo "</div><div class='item-wrap'>";
}
}
?>
</div>
<?php
}
I have created a yii based project. I have a view where we show data from a database. I want to print that page. I searched and found the printout extension for printing and I copied the 'print' directory to /protected/extensions, but we can not understand how we could use it on my view page to print it.
My view page:
<div class="row">
<div class="row-column1">
<?php echo CHtml::label('Reg. Number. :','student_enroll_no'); ?>
<?php echo $info->student_enroll_no;?>
</div>
<div class="row-column2">
<?php echo CHtml::label('Adm. Date :','student_adm_date'); ?>
<?php if($info->student_adm_date != NULL)
echo date('d-m-Y',strtotime($info->student_adm_date));?>
</div>
</div>
<div class="row">
<div class="row-column1">
<?php echo CHtml::label('Student Name :','student_first_name'); ?>
<?php echo $info->student_first_name;?>
</div>
<div class="row-column2">
<?php echo CHtml::label('Enroll No. :','student_mobile_no'); ?>
<?php echo $info->student_mobile_no;?>
</div>
</div>
<div class="row">
<div class="row-column1">
<?php echo CHtml::label('Fathers Name :','student_last_name'); ?>
<?php echo $info->student_last_name;?>
<!--<?php echo CHtml::label('Gender :','student_gender'); ?>
<?php echo $info->student_gender;?>-->
</div>
<div class="row-column3">
<?php echo CHtml::label('Mothers Name :','student_mother_name'); ?>
<?php echo $info->student_mother_name;?>
<!-- <?php echo CHtml::label('Date of Birth :','student_dob'); ?>
<?php if($info->student_dob != NULL)
echo date('d-m-Y',strtotime($info->student_dob));?>-->
</div>
</div>
<div class="row">
<div class="row-column1">
<?php echo CHtml::label('Gender :','student_gender'); ?>
<?php echo $info->student_gender;?>
<!--<?php echo CHtml::label('Course :','student_transaction_course_id'); ?>
<?php
echo !empty($model->student_transaction_course_id) ? $model->relCourse->course_name : 'N/A';
?>-->
</div>
<div class="row-column2">
<?php echo CHtml::label('Date of Birth :','student_dob'); ?>
<?php if($info->student_dob != NULL)
echo date('d-m-Y',strtotime($info->student_dob));?>
<!--<?php echo CHtml::label('Year :','student_academic_term_period_tran_id'); ?>
<?php echo $model->Rel_student_academic_terms_period_name->academic_term_period;?>-->
</div>
</div>
<div class="row">
<div class="row-column1">
<?php echo CHtml::label('Category :','title'); ?>
<?php echo $info->title;?>
</div>
<div class="row-column2">
<?php echo CHtml::label('Email ID :','student_email_id_1'); ?> <?php echo $info->student_email_id_1; ?>
</div>
</div>
<div class="row">
<div class="row-left">
<?php echo CHtml::label('Course :','student_transaction_course_id'); ?>
<?php
echo !empty($model->student_transaction_course_id) ? $model->relCourse->course_name : 'N/A';
?>
<!-- <?php echo CHtml::label('Blood Group :','student_living_status'); ?>
<?php echo $info->student_living_status; ?>-->
</div>
<div class="row-column3">
<!-- <?php echo CHtml::label('Nationality :','student_transaction_nationality_id'); ?>
<?php if($model->student_transaction_nationality_id!=null)
echo $model->Rel_Nationality->nationality_name;
?>-->
<?php echo CHtml::label('Year :','student_academic_term_period_tran_id'); ?>
<?php echo $model->Rel_student_academic_terms_period_name->academic_term_period;?>
</div>
</div>
<div class="row">
<div class="row-left">
<?php echo CHtml::label('Subjects :','languages_known1'); ?>
<?php
$knwLang = "";
if($lang->languages_known1)
$knwLang = $lang->Rel_Langs1->languages_name;
if($lang->languages_known2)
$knwLang .= ", ".$lang->Rel_Langs2->languages_name;
if($lang->languages_known3)
$knwLang .= ", ".$lang->Rel_Langs3->languages_name;
echo $knwLang;
?>
</div>
</div>
<div class="row last">
<?php echo ('_____________________Note -Click on edit and update DoB , Subjects and upload photo ,Enroll no. .'); ?>
</div>
The documentation for this extension says it is tuned for the dataGrid widget. However it seems you are not using the dataGrid widget so what you can do is override the default printedElement property.
For example:
Wrap all the elements you wish to print in a div and give it an id of #printme and add the following to your view.
<?php
$this->widget('application.extensions.print.printWidget', array(
'cssFile' => 'print.css',
'printedElement'=>'#printme',
)
)
);
?>
NOTE: Don't forget to add/edit the print.css file.
Read the documentation for more options:
http://www.yiiframework.com/extension/printout