Display rows including empty rows in symfony 1 - php

I'm a newbie in web development, and i want to modify an existing project.I want to display rows including a null value,a default value of zero or the empty one.This is the code in action..
public function executeDetails(sfWebRequest $r) {
if($this->getUser()->hasAttribute('extend_term_ch')) {
$this->getUser()->getAttributeHolder()->remove('extend_term_ch');
}
$this->loan = Doctrine_Core::getTable('Loans')->findOneById($r->getParameter('id'));
$this->debits = Doctrine_Core::getTable('CreditLogs')->getByLoanId($r->getParameter('id'));
}
and in templates
<?php $totalAmount = 0 ?>
<?php foreach($loan->Collections as $i=>$c): ?>
<?php $totalAmount += $c->amount ?>
<tr class="<?php echo ($i%2==0)?'even':'odd' ?>">
<td>
<?php echo $c->mode_of_payment ?>
<?php if($c->mode_of_payment == 'Cheque'): ?>
<?php $cReferencedObj = $c->Cheques ?>
<div class="small_detail info">
<span class="bold">(<?php echo $cReferencedObj->bank ?>, <?php echo $cReferencedObj->branch ?>) <?php echo $cReferencedObj->reference_number ?></span>
</div><br />
<?php endif; ?>
<?php $replaced = $c->getReplacedCheque() ?>
<?php if(!empty($replaced)): ?>
<div class="small_detail info">
Payment for <span class="bold">(<?php echo $replaced->bank ?>, <?php echo $replaced->branch ?>) <?php echo $replaced->reference_number ?></span>
</div><br />
<?php endif; ?>
</td>
<td><?php echo $c->batch_no ?></td>
<td>
PHP <?php echo number_format($c->amount, 2) ?>
<?php if($c->mode_of_payment == 'Cheque' && !empty($c->Cheques->replaced_with)): ?>
<?php $replaced = $c->Cheques->Replaced ?>
<div class="small_detail info">
Replaced with <span class="bold">(<?php echo $replaced->bank ?>, <?php echo $replaced->branch ?>) <?php echo $replaced->reference_number ?></span>
</div>
<?php endif; ?>
</td>
<td><?php echo date('F d, Y', strtotime($c->date_created)) ?></td>
<td><?php echo $c->created_by ?></td>
<td><?php echo $c->date_created ?></td>
<td>
<?php if(in_array($c->mode_of_payment, array('Cheque', 'ATM', 'Direct Bank Transfer'))): ?>
<span class="info">
View Details
</span>
<?php else: ?>
<div class="small_detail info">
Collector: <span class="bold"><?php echo $c->Collectors->lastname.', '.$c->Collectors->firstname ?></span>
</div>
<?php endif; ?>
<?php if(in_array($loan->mode_of_payment, array('Cash', 'ATM')) && $sf_user->hasCredential('COLLECTIONS_ROLLBACK')): ?>
<div class="small_detail bullet_go">
Rollback Collection
</div>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="6">Total Paid</td>
<td>PHP <?php echo number_format($totalAmount, 2) ?></td>
</tr>
This will only display rows with data..how about displaying the empty row?For example a person has to pay his debts in 40 days from April 1, 2014 up to March 10,2014, then for some reason, he did not pay April 4, 6, 8 and so on.I want to display those dates 4, and 6 and 8 and display some errors for every date he failed to pay it like "No payment for this date".

Related

Adding serial number to the table

I have this PHP code that displays data from the MySQL database. I would like to add a serial number for which I tried with the following code but it doesn't work as it's not in the loop and also it doesn't know endpoint and so I have max at 12:
<?php foreach (range(0, 12) as $number) { echo $number; }?>
Here's the main PHP code. How do I add a serial number to the <td> block:
<tbody>
<?php foreach ($items as $i => $item) : ?>
<tr id="tablelist_item_<?php echo $i; ?>" class="<?php echo $fc_item_classes.' row'.($i%2 ? 1 : 0); ?>" <?php echo $microdata_itemtype_code; ?>>
<?php if ( $buttons_exists || $show_title || count($item->css_markups) ) : ?>
<td><?php foreach (range(0, 12) as $number) { echo $number; }?></td>
<td class="fc_title_col">
<?php if ($show_title) : ?>
<!-- BOF item title -->
<span class="fc_item_title" itemprop="name">
<?php if ($link_titles) : ?>
<?php echo $item->title; ?>
<?php else : ?>
<?php echo $item->title; ?>
<?php endif; ?>
</span>
<!-- EOF item title -->
<?php endif; ?>
<div class="fcclear fc_beforemarkups"></div>
</td>
<?php endif; ?>
<!-- BOF item fields -->
<?php foreach ($columns as $name => $label) : ?>
<td><?php echo isset($item->positions['table']->{$name}->display) ? $item->positions['table']->{$name}->display : ''; ?></td>
<?php endforeach; ?>
<!-- EOF item fields -->
</tr>
<?php endforeach; ?>
</tbody>
I ended up with this: <td><?php echo ($i+1); ?></td>
and it works :)

Grouped Product won't be added to cart and there is a message "Please specify the quantity of product(s)."

I am developing a store and the product I tried to add is a grouped product which I had done some design and configuration on the front end. Then, I added sample grouped product and when I click "Add to cart" , there is message "Please specify the quantity of product(s)."
Please see the website (Sorry the website is in Thai but you can try to increase the Quantity of each product and then click add to cart - Pink button)
http://www.preciosathailand.com/eyeline-0001.html
This is PHP code that I made the configuration
<?php if ($_hasAssociatedProducts): ?>
<?php foreach ($_associatedProducts as $_item): ?>
<?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
<tr>
<td width="80%"><span class="product-<?php echo $_item->getId() ?>"><?php echo $this->escapeHtml($_item->getName()) ?></span></td>
<?php if ($this->getCanShowProductPrice($_product)): ?>
<td class="a-right">
<?php if ($this->getCanShowProductPrice($_item)): ?>
<?php echo $this->getPriceHtml($_item, true) ?>
<?php echo $this->getTierPriceHtml($_item) ?>
<?php endif; ?>
</td>
<?php endif; ?>
<?php if ($_product->isSaleable()): ?>
<td class="a-center" width="20%">
<?php if ($_item->isSaleable()) : ?>
<div class="qty-tools">
<div class="minus-qty minus-<?php echo $_item->getId() ?>"><a class="click-to-minus" id="minus-<?php echo $_item->getId() ?>" href="#" data-id-p="<?php echo $_item->getId() ?>">-</a></div>
<div class="input-qty-wrapper">
<input type="text" name="super_group[<?php echo $_item->getId() ?>]" data-qty-product-id="<?php echo $_item->getId() ?>" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
</div>
<div class="plus-qty plus-<?php echo $_item->getId() ?>"><a class="click-to-plus" href="#" id="plus-<?php echo $_item->getId() ?>" data-id-p="<?php echo $_item->getId() ?>">+</a></div>
</div>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
</tr>
<?php endif; ?>
This is jQuery that I have done.
jQuery(document).ready(function(){
jQuery('.click-to-minus').click(function(){
var IDInput = jQuery(this).data('id-p');
var CurrentVal = jQuery('input[name="super_group['+IDInput+']"]').val();
var minusedVal = CurrentVal-1;
jQuery('input#'+IDInput).val(minusedVal);
});
jQuery('.click-to-plus').click(function(){
var pIDInput = jQuery(this).data('id-p');
var CurrentPlusVal = jQuery('input[name="super_group['+pIDInput+']"]').val();
/* if ( CountPlus == 0){
var plusedVal = 1;
}else{
jQuery('input#'+pIDInput).val('');
var plusedVal = CurrentPlusVal+1;
}*/
var plusedVal = +CurrentPlusVal+1;
jQuery('input[data-qty-product-id="'+pIDInput+'"]').val(plusedVal);
});
});
Did I do anything wrong?
Are you trying to group configurable products, then you should know that magento doesnt allow it.
you can check this answer here

PHP/CSS & Alignment of Columns

I started learning PHP/CSS/HTML5 & Java a month ago and I'm currently setting up an online shop for my new home business. I'm using opencart, but i'm having difficulty with transforming some of the PHP in terms of getting it to display side by side.
This is how I would like it to look.
Price: $000.00000
<table width="200" border="0">
<tr>
<td>Option 1</td>
<td>Option 2</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
</tr>
</table>
I've figured out how to do this in CSS, but the required radio radio buttons (see the code below) is the same code for option 1 & 2.
It currently looks like this
Price $000.0000
Option 1
1
2
3
Option 2
1
2
3
<?php if ($price) { ?>
<div class="price">
<span class="text-price"><?php echo $text_price; ?></span>
<?php if (!$special) { ?>
<span class="price-new"><?php echo $price; ?> <span style="font-size:10px;">pp</span></span>
<?php } else { ?>
<span class="price-new"><?php echo $special; ?></span><span class="price-old"><?php echo $price; ?></span>
<?php } ?>
<?php if ($tax) { ?>
<span class="price-tax"><?php echo $text_tax; ?> <?php echo $tax; ?></span>
<?php } ?>
<?php if ($points) { ?>
<span class="reward"><small><?php echo $text_points; ?> <?php echo $points; ?></small></span>
<?php } ?>
<?php if ($discounts) { ?>
<div class="discount">
<?php foreach ($discounts as $discount) { ?>
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?><br />
<?php } ?>
</div>
<?php } ?>
</div>
<?php } ?>
<?php if ($profiles): ?>
<div class="option">
<h2><span class="required">*</span><?php echo $text_payment_profile ?></h2>
<br />
<select name="profile_id">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($profiles as $profile): ?>
<option value="<?php echo $profile['profile_id'] ?>"><?php echo $profile['name'] ?></option>
<?php endforeach; ?>
</select>
<br />
<br />
<span id="profile-description"></span>
<br />
<br />
</div>
<?php endif; ?>
<?php if ($options) { ?>
<div class="options">
<h2><?php echo $text_option; ?></h2>
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<label><?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b></label>
<select name="option[<?php echo $option['product_option_id']; ?>]">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
</div>
<?php } ?>
<?php if ($option['type'] == 'radio') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<label>
<?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b></label>
<?php foreach ($option['option_value'] as $option_value) { ?>
<label class="radio" for="option-value-<?php echo $option_value['product_option_value_id']; ?>">
<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" /><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</label>
<?php } ?>
Why don't you display your table dynamically and then simply style it in CSS using nth-child(#)? You can simply loop through an array and display echo each row before closing out the table after.

osclass specific category at home page

I am using osclass 3.1.2 version with modern theme. I have created 2 main categories paid and free which also contains one subcategory each named as premium ads and free ads. now I want to display only premium ads on my sites home page so how can I do this?
I have found this code from http://doc.osclass.org/Display_only_certain_type_of_listings
But not able to merge with my code please help.
thanks for replies. finally i have found my answer.following code is perfect solution of my problem.
<?php osc_query_item("category=99");
if( osc_count_custom_items() == 0) { ?>
<p class="empty"><?php _e('No Listings', 'modern') ; ?></p>
<?php } else { ?>
<table border="0" cellspacing="0">
<tbody>
<?php $class = "even"; ?>
<?php while ( osc_has_custom_items() ) { ?>
<tr class="<?php echo $class. (osc_item_is_premium()?" premium":"") ; ?>">
<?php if( osc_images_enabled_at_items() ) { ?>
<td class="photo">
<?php if( osc_count_item_resources() ) { ?>
<a href="<?php echo osc_item_url() ; ?>">
<img src="<?php echo osc_resource_thumbnail_url() ; ?>" width="75" height="56" title="<?php echo osc_item_title(); ?>" alt="<?php echo osc_item_title(); ?>" />
</a>
<?php } else { ?>
<img src="<?php echo osc_current_web_theme_url('images/no_photo.gif') ; ?>" alt="" title=""/>
<?php } ?>
</td>
<?php } ?>
<td class="text">
<h3><?php echo osc_item_title() ; ?></h3>
<p><strong><?php if( osc_price_enabled_at_items() ) { echo osc_item_formated_price() ; ?> - <?php } echo osc_item_city(); ?> (<?php echo osc_item_region();?>) - <?php echo osc_format_date(osc_item_pub_date()); ?></strong></p>
<p><?php echo osc_highlight( strip_tags( osc_item_description() ) ) ; ?></p>
</td>
</tr>
<?php $class = ($class == 'even') ? 'odd' : 'even' ; ?>
<?php } ?>
</tbody>
</table>
<?php }; ?>

Magento - pull one single customer review

I've been trying to pull one single customer review onto the product page.
I've no code to show as honestly i'm not sure where to start and can't find any mention of it online.
Anyone have any ideas?
I wrote a tutorial earlier on bringing all the review elements onto the product page, so you could follow this tutorial: http://www.e-commercewebdesign.co.uk/blog/magento-tutorials/product-reviews-on-product-view-page.php
All you'd have to do is rename the list block and bring it out in the same way. Then simply modify the loop which brings out the reviews in any way you see fit. E.g. limit to a certain number or only echo out review from a certain user.
EDIT:
To get the latest review is quite simple because the reviews are in date order anyway.
Go to review > product > list.phtml
Replace the code in that file with this:
<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<h2><?php echo $this->__('Customer Reviews') ?></h2>
<?php echo $this->getChildHtml('toolbar') ?>
<dl>
<?php $r_count = 0; ?>
<?php foreach ($_items as $_review):?>
<?php if ($r_count == 0) { ?>
<dt>
<?php echo $this->htmlEscape($_review->getTitle()) ?> <?php echo $this->__('Review by <span>%s</span>', $this->htmlEscape($_review->getNickname())) ?>
</dt>
<dd>
<?php $_votes = $_review->getRatingVotes(); ?>
<?php if (count($_votes)): ?>
<table class="ratings-table">
<col width="1" />
<col />
<tbody>
<?php foreach ($_votes as $_vote): ?>
<tr>
<th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
<td>
<div class="rating-box">
<div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php echo nl2br($this->htmlEscape($_review->getDetail())) ?>
<small class="date"><?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?></small>
</dd>
<?php } ?>
<?php $r_count++; ?>
<?php endforeach; ?>
</dl>
<?php echo $this->getChildHtml('toolbar') ?>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>
</div>
I've simple put an interator into the loop $r_count and put a check inside the foreach which prevent it from progressing on the next loop iteration.

Categories