I am trying to get some custom attributes to show in magento like Color, Delivery_Time...
I could call Some Attributes with :
<?php echo $item->getName();?>
<?php echo $item->getWeight();?>
But i could'nt call the most of the attributes. i've tried also :
<?php echo $this->htmlEscape($item->getData('luftkammern'));?>
<?php echo $item->getAttributeText('spannung'); ?>
Nothing works!!
Code of attributes :
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<h2><?php echo $this->__('Additional Information') ?></h2>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product,$_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>
code
echo $this->__('Additional Information');?>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
can anyone help please ?
If you need to get those attributes in checkout page, you can do like this :
$_product = $item->getProduct();
$pid = $_product->getId();
$product = Mage::getModel('catalog/product')->load($pid);
/* getting some attributes */
$color = $product->getData('color');
$manufacturer = $product->getData('manufacturer');
$delivery_date = $product->getData('delivery_date');
....
Hope it will help you.
You can get attributes from a product by calling the correct get function.
For example to receive the color use:
echo $item->getColor();
To receive the manufacturer use:
echo $item->getManufacturer();
Also you have to make sure that your product has been fully loaded. Try this:
print_r($item->getData());
Please check the following code:
$attributes = $product->getAttributes();
$additional_data = array();
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront() && $attribute->getIsUserDefined()) {
$value = $attribute->getFrontend()->getValue($product);
if (!$product->hasData($attribute->getAttributeCode())) {
$value = Mage::helper('catalog')->__('N/A');
} elseif ((string)$value == '') {
$value = Mage::helper('catalog')->__('No');
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
$value = Mage::app()->getStore()->convertPrice($value, true);
}
if (is_string($value) && strlen($value)) {
$additional_data[$attribute->getAttributeCode()] = array(
'label' => $attribute->getStoreLabel(),
'value' => $value,
'code' => $attribute->getAttributeCode()
);
}
}
}
/* Your code here */
<h2><?php echo $this->__('Additional Information') ?></h2>
...
<?php foreach ($additional_data as $_data): ?>
...
Related
I have two tables meals type and meals. I want to print each meals corresponding to its meals type.
Error is that only showing last meals type meals only
view page is like
View
<?php
foreach ($mealstype as $type) {
?>
<h2><?php echo $type->type; ?></h2>
<table class="table table-bordered">
<tr>
<th>Meals</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php
foreach ($meals as $meals_get) {
?>
<tr>
<td><?php echo $meals_get->item; ?></td>
<td><?php echo $meals_get->price; ?></td>
</tr>
<?php } ?>
<tr>
<td> <input type="checkbox" class="ck" value="total"> Toal</td>
<td>2050</td>
</tr>
</tbody>
</table>
<?php
}
?>
Controller
function availability() {
$this->data['mealstype'] = $this->Home_model->mealstype();
foreach ($this->data['mealstype'] as $type) {
$typeid = $type->id;
$meals[] = $this->Home_model->meals($typeid, $hotel_id);
}
$this->data['meals'] = $meals[];
$this->load->view('home2', $this->data);
}
Please check this answer
Controller:
public function availability() {
$build_array = array();
mealstype= $this->Home_model->mealstype();
foreach($mealstype as $row){
$build_array[] = array(
'parent_array' => $row,
'child_array' =>$this->Home_model->meals($row->id,$hotel_id),
'child_sum' =>$this->Home_model->meals_sum($row->id,$hotel_id)
);
}
$this->data['build_array'] = $build_array;
}
and the view page is like this:
View:
<?php foreach($build_array as $type){?>
<h2><?php echo $type['parent_array']->type;?></h2>
<table class="table table-bordered">
<tr>
<th>Meals</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php
foreach ($type["child_array"] as $meals_get) {?>
<tr>
<td><?php echo $meals_get->item;?></td>
<td><?php echo $meals_get->price;?></td>
</tr>
<?php }?>
<tr>
<td> Toal</td>
<td>2050</td>
</tr>
<?php } ?>
Controller, check "hotel_id"
function availability()
{
$this->data['mealstype'] = $this->Home_model->mealstype();
if( count( $this->data['mealstype'] ) > 0 )
{
foreach($this->data['mealstype'] as $type)
{
$type->meals = $this->Home_model->meals( $type->id, $hotel_id ); // hotel_id no declared???
}
}
$this->load->view('home2', $this->data);
}
View
<?php if( count( $mealstype ) > 0): foreach( $mealstype as $type ): ?>
<h2><?php echo $type->type; ?></h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Meals</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php if( count( $type->meals ) > 0 ): foreach( $type->meals as $meals_get ): ?>
<tr>
<td><?php echo $meals_get->item; ?></td>
<td><?php echo $meals_get->price; ?></td>
</tr>
<?php endforeach; endif; ?>
<tr>
<td><input type="checkbox" class="ck" value="total"> Toal</td>
<td>2050</td>
</tr>
</tbody>
</table>
<?php endforeach; endif ?>
Try to replace into this :
function availability() {
$data = array();
$data['mealstype'] = $this->Home_model->mealstype();
foreach ($data['mealstype'] as $type) {
$typeid = $type->id;
$type->meals = $this->Home_model->meals($typeid,$hotel_id);
}
$this->load->view('home2', $data);
}
check it and print_r($data); what it comes set on the basis of that in view file..
You have $hotel_id I am not sure where you set this I can not see it any where else.
We also need to see your model
public function availability() {
$data['mealstypes'] = array();
$mealstypes = $this->home_model->mealstype();
foreach ($mealstypes as $mealstype)
{
$meals = array();
$meals_results = $this->home_model->meals($mealstype->id, $hotel_id);
foreach ($meals_results $meal_result) {
$meals[] = array(
'mealstype' => $meal_result->mealstype,
'price' => $meal_result->price
);
}
$data['mealstypes'][] = array(
'type' => $mealstype->type
'meals' => $meals
);
}
$this->load->view('someview', $data);
}
View
<?php foreach ($mealstypes as $mealstype) {?>
<h2><?php echo $mealstype['type'];?></h2>
<?php foreach ($mealstype['meals'] as $meal) {?>
<?php echo $meal['mealstype'];?>
<?php echo $meal['price'];?>
<?php }?>
<?php }?>
I try to get product details on my checkout success page in Magento 1.9, but I don't know why I get the same product for two times. This is what I add in the app/design/frontend/base/default/template/checkout/success.phtml file
<tbody>
<?php
foreach ($items as $item):
$_product = Mage::getModel('catalog/product')->load($item->getProductId());
$productType = $_product->getTypeId();
$entityId = $_product->getEntityId();
$options = $item->getProductOptions();
if ($productType == "bundle") {
$bundled_product = new Mage_Catalog_Model_Product();
$bundled_product->load($entityId);
$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection( $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product );
$bundled_items = array();
foreach ($selectionCollection as $option) {
$bundled_items[] = $option->product_id;
}?>
<tr>
<td rowspan="1">
<img class="product_img" src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75); ?>" alt="product-img" />
<?php echo $item->getName();
$customOptions = $options['options'];
if (!empty($customOptions)) {
foreach ($customOptions as $option) {?>
<span class="bottom-align">
<?php
echo '<b>' . $option['label'] . '</b> :';
echo $optionValue = $option['value'];
?>
</span>
<?php
}
}
?>
</td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getPrice()); ?></td>
<td><?php echo $item->getQtyOrdered(); ?></td>
<td><?php echo $item->getSku(); ?></td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getRowTotal()); ?></td>
</tr>
<?php
} else if (in_array($entityId, $bundled_items)) {
} else {
?>
<tr>
<td>
<img class="product_img" src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75); ?>" alt="product-img" />
<?php
echo $item->getName();
$customOptions = $options['options'];
if (!empty($customOptions)) {
foreach ($customOptions as $option) {
?>
<span class="bottom-align">
<?php
echo '<b>' . $option['label'] . '</b> :';
echo $optionValue = $option['value'];
?></span>
<?php
}
}
?>
</td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getPrice()); ?></td>
<td><?php echo $item->getQtyOrdered(); ?></td>
<td><?php echo $item->getSku(); ?></td>
<td><?php echo $this->helper('checkout')->formatPrice($item->getRowTotal()); ?></td>
</tr>
<?php
}
?>
<?php endforeach ?>
</tbody>
This is the expected behaviour. There are several rows inserted into database for composite products: bundles, configurables.
In your case first one is a bundle product himself, second one is a selected simple product.
You can replace } else { with } elseif (!$item->getParentId()) { in your template to skip child simple product.
I updated WooCommerce to the latest version and now - in the checkout - the available payment methods are shown two times right after eachother as shown in the screenshot below.
In my WooCommerce files I found that the review-order.php file generate this page. I found the file here: /wp-content/themes/[mytheme]/woocommerce/checkout
Please note that there is some custom code in there - this might be the cause of this?
I know that everything within the tag is generating the payment method view but I cant figure out why it generates two of them.
I apologize for the long code. I was not sure what to include or exclude.
I hope you are able to help me out!
The review-order.php file:
<?php
global $woocommerce;
$available_methods = $woocommerce->shipping->load_shipping_methods();
?>
<div id="order_review" class="order_review">
<h2 id="order_review_heading"><?php _e('Betalingsoversigt', 'academy'); ?></h2>
<table class="shop_table" style="display:block;">
<tbody>
<?php
do_action('woocommerce_review_order_before_cart_contents');
if (sizeof($woocommerce->cart->get_cart()) > 0) :
foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
$_product = $values['data'];
if ($_product->exists() && $values['quantity'] > 0) :
echo '
<tr class="' . esc_attr(apply_filters('woocommerce_checkout_table_item_class', 'checkout_table_item', $values, $item_id)) . '">
<td class="product-name">' . $_product->get_title() . ' <strong class="product-quantity">× ' . $values['quantity'] . '</strong>' . $woocommerce->cart->get_item_data($values) . '</td>
<td class="product-total">' . apply_filters('woocommerce_checkout_item_subtotal', $woocommerce->cart->get_product_subtotal($_product, $values['quantity']), $values, $item_id) . '</td>
</tr>';
endif;
endforeach;
endif;
do_action('woocommerce_review_order_after_cart_contents');
?>
</tbody>
<tfoot>
<tr class="cart-subtotal">
<th><?php _e('Subtotal', 'academy'); ?></th>
<td><?php echo $woocommerce->cart->get_cart_subtotal(); ?></td>
</tr>
<?php if ($woocommerce->cart->get_discounts_before_tax()) : ?>
<tr class="discount">
<th><?php _e('Rabat', 'academy'); ?></th>
<td>-<?php echo $woocommerce->cart->get_discounts_before_tax(); ?></td>
</tr>
<?php endif; ?>
<?php if ($woocommerce->cart->needs_shipping() && $woocommerce->cart->show_shipping()) : ?>
<?php do_action('woocommerce_review_order_before_shipping'); ?>
<tr class="shipping">
<th><?php _e('Levering', 'academy'); ?></th>
<td><?php woocommerce_get_template('cart/shipping-methods.php', array('available_methods' => $available_methods)); ?></td>
</tr>
<?php do_action('woocommerce_review_order_after_shipping'); ?>
<?php endif; ?>
<?php foreach ($woocommerce->cart->get_fees() as $fee) : ?>
<tr class="fee fee-<?php echo $fee->id ?>">
<th><?php echo $fee->name ?></th>
<td>
<?php
if ($woocommerce->cart->tax_display_cart == 'excl')
echo woocommerce_price($fee->amount);
else
echo woocommerce_price($fee->amount + $fee->tax);
?>
</td>
</tr>
<?php endforeach; ?>
<?php
if ($woocommerce->cart->tax_display_cart == 'excl') {
$taxes = $woocommerce->cart->get_taxes();
if (sizeof($taxes) > 0) {
$has_compound_tax = false;
foreach ($taxes as $key => $tax) {
if ($woocommerce->cart->tax->is_compound($key)) {
$has_compound_tax = true;
continue;
}
?>
<tr class="tax-rate tax-rate-<?php echo $key; ?>">
<th><?php echo $woocommerce->cart->tax->get_rate_label($key); ?></th>
<td><?php echo $tax; ?></td>
</tr>
<?php
}
if ($has_compound_tax) {
?>
<tr class="order-subtotal">
<th><?php _e('Subtotal', 'academy'); ?></th>
<td><?php echo $woocommerce->cart->get_cart_subtotal(true); ?></td>
</tr>
<?php
}
foreach ($taxes as $key => $tax) {
if (!$woocommerce->cart->tax->is_compound($key))
continue;
?>
<tr class="tax-rate tax-rate-<?php echo $key; ?>">
<th><?php echo $woocommerce->cart->tax->get_rate_label($key); ?></th>
<td><?php echo $tax; ?></td>
</tr>
<?php
}
} elseif ($woocommerce->cart->get_cart_tax()) {
?>
<tr class="tax">
<th><?php _e('Tax', 'academy'); ?></th>
<td><?php echo $woocommerce->cart->get_cart_tax(); ?></td>
</tr>
<?php
}
}
?>
<?php if ($woocommerce->cart->get_discounts_after_tax()) : ?>
<tr class="discount">
<th><?php _e('Order Discount', 'academy'); ?></th>
<td>-<?php echo $woocommerce->cart->get_discounts_after_tax(); ?></td>
</tr>
<?php endif; ?>
<?php do_action('woocommerce_review_order_before_order_total'); ?>
<tr class="total">
<th><strong><?php _e('Total', 'academy'); ?></strong></th>
<td>
<strong><?php echo $woocommerce->cart->get_total(); ?></strong>
<?php
if ($woocommerce->cart->tax_display_cart == 'incl') {
$tax_string_array = array();
$taxes = $woocommerce->cart->get_formatted_taxes();
if (sizeof($taxes) > 0) {
foreach ($taxes as $key => $tax) {
$tax_string_array[] = sprintf('%s %s', $tax, $woocommerce->cart->tax->get_rate_label($key));
}
} elseif ($woocommerce->cart->get_cart_tax()) {
$tax_string_array[] = sprintf('%s tax', $tax);
}
if (!empty($tax_string_array)) {
?><small class="includes_tax"><?php printf(__('(Includes %s)', 'academy'), implode(', ', $tax_string_array)); ?></small><?php
}
}
?>
</td>
</tr>
<?php do_action('woocommerce_review_order_after_order_total'); ?>
</tfoot>
</table>
</div>
<div id="payment">
<div id="price"><?php ?></div>
<?php
global $current_user;
$current_user_role = get_user_meta($current_user->data->ID, 'user_role');
?>
<?php if ($woocommerce->cart->needs_payment()) : ?>
<div class="accordion toggles-wrap payment-listing">
<?php
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
if ($available_gateways) :
$counter = 0;
if (sizeof($available_gateways)) :
$custom_gateway = get_option('woocommerce_default_gateway');
if ($current_user_role[0] == 'private_person') {
$custom_gateway = 'epay_dk';
}
if ($current_user_role[0] == 'driving_school_student') {
$custom_gateway = 'cod';
}
if ($current_user_role[0] == 'company') {
$custom_gateway = 'cod';
}
$default_gateway = $custom_gateway;
if (isset($_SESSION['_chosen_payment_method']) && isset($available_gateways[$_SESSION['_chosen_payment_method']])) :
$available_gateways[$_SESSION['_chosen_payment_method']]->set_current();
elseif (isset($available_gateways[$default_gateway])) :
$available_gateways[$default_gateway]->set_current();
else :
current($available_gateways)->set_current();
endif;
endif;
foreach ($available_gateways as $gateway) :
?>
<div class="toggle-container <?php if ($gateway->get_title() == $payment_def) echo 'expanded'; ?>" >
<label for="payment_method_<?php echo $gateway->id; ?>" class="toggle-title"><h5 class="nomargin"><?php echo $gateway->get_title(); ?></h5></label>
<input type="radio" id="payment_method_<?php echo $gateway->id; ?>" class="hidden" name="payment_method" value="<?php echo esc_attr($gateway->id); ?>" <?php if ($gateway->chosen) echo 'checked="checked"'; ?> />
<?php if ($gateway->has_fields() || $gateway->get_description()) : ?>
<div class="toggle-content payment_method_<?php echo $gateway->id; ?>"><?php $gateway->payment_fields(); ?></div>
<?php endif; ?>
</div>
<?php
$counter++;
endforeach;
endif;
?>
</div>
<?php endif; ?>
<div class="form-row place-order">
<?php $woocommerce->nonce_field('process_checkout') ?>
<?php if (woocommerce_get_page_id('terms') > 0) : ?>
<div class="terms">
<input type="checkbox" class="input-checkbox" name="terms" <?php checked(isset($_POST['terms']), true); ?> id="terms" />
<label for="terms" class="checkbox"><?php _e('Jeg accepterer', 'academy'); ?> <?php _e('Reddernes Vilkår', 'academy'); ?></label>
</div>
<?php endif; ?>
<?php do_action('woocommerce_review_order_before_submit'); ?>
<input type="submit" class="button alt place-order-button" name="woocommerce_checkout_place_order" id="place_order" value="<?php echo apply_filters('woocommerce_order_button_text', __('Betal nu', 'academy')); ?>" />
<?php do_action('woocommerce_review_order_after_submit'); ?>
</div>
</div>
</div>
<style>.woocommerce-checkout .checkout .order_review table.shop_table td{ width: 100%;}#payment #price .total p{ text-align: right;}</style>
Here is a code.
This loads all the header part (i.e the header for the table) dynamically from the database.
The below code works fine. But the column is mismatched.
i.e. the first row first column of the header is blank and there is a dislocation in the table.
Code
<table border="1">
<?php
$book_query = mysql_query("select * from book_master");
$i = 0;
while($row = mysql_fetch_assoc($book_query))
{
$columns = array_keys($row);
?>
<th>
<?php
foreach($columns as $column)
{
?>
<td><?php echo $column; ?> </td>
</th>
<?php
}
?>
<tr>
<?php
foreach($row as $key=>$value)
{
?>
<td><?php echo $value; ?></td>
<?php
}
?>
</tr>
<?php
$i++;
}
?>
</table>
EDIT:
Here is my print_r($columns) value:
Array ( [0] => Author Name [1] => Book Name [2] => Rating [3] => Location )
I know the problem is with the loop. Could someone help me out?
You can try to change
<th>
<?php
foreach($columns as $column)
{ ?>
<td><?php echo $column; ?> </td>
<?php
}
?>
</th>
to
<tr>
<?php
foreach($columns as $column)
{ ?>
<th><?php echo $column; ?> </th>
<?php
}
?>
</tr>
Just remove TH tag because its create one extra cell, so your layout messed up
<table border="1">
<?php
$book_query = mysql_query("select * from book_master");
$i = 0;
while($row = mysql_fetch_assoc($book_query))
{
if($i == 0){
$columns = array_keys($row);
?>
<?php
foreach($columns as $column){ ?>
<td><?php echo $column; ?> </td>
<?php } ?>
<?php } ?>
<tr>
<?php
foreach($row as $key=>$value){ ?>
<td><?php echo $value; ?></td>
<?php } ?>
</tr>
<?php
$i++;
}
?>
</table>
Hope this will help someone.
Just I have replaced the TH tag with TR and the output is perfect.
<table border="1">
<?php
$book_query = mysql_query("select * from book_master");
while($row = mysql_fetch_assoc($book_query))
{
$columns = array_keys($row);
?>
<tr>
<?php
foreach($columns as $column){ ?>
<td><?php echo $column; ?> </td>
<?php } ?>
</tr>
<tr>
<?php
foreach($row as $key=>$value){ ?>
<td><?php echo $value; ?></td>
<?php } ?>
</tr>
</table>
I'm trying to write some sort of forum homepage, based off work someone else did. Here's what I've got so far:
Forums
<?php
$crumbs = explode(",", $user['data']['depts']);
foreach ($crumbs as &$value) {
$data = $db->query("SELECT * FROM tbl_depts WHERE id = '" . $value . "'");
$crumb = $data->fetch_assoc();
$data = $db->query("SELECT * FROM tbl_forums WHERE deptid = '" . $value . "'");
$forumcount = $data->num_rows;
$forum = $data->fetch_assoc();
?>
<div class="h3top"><?php echo $crumb['name']; ?></div>
<div class="info2alt">
<?php
while (($row = $data->fetch_array()) !== FALSE) {
$forum[] = $row;
}
foreach ($forum as $row) {
if ($forumcount >= 1) {
if ($forum['lastpost'] == "") {
$forum['lastpost'] = "--";
}
?>
<div class="info4">
<table width="100%" border="0" cellspacing="1" cellpadding="4">
<tr>
<td width="55%" align="left" valign="middle" class="zebraodd"><?php echo $row['name']; ?></td>
<td width="10%">Threads: <?php echo $forum['threadcount']; ?><br />Posts: <?php echo $forum['postcount']; ?></td>
<td width="35%">Last Post: <?php echo $forum['lastpost']; ?></td>
</tr>
</table>
</div>
<?php
}
?>
<?php if ($forumcount >= 1) { ?>
<div class="info3bottom"></div>
<?php
}
}
?>
</div>
<?php
}
?>
This is the current data in the table:
Now, when I try to use this code, I get this:, such that the first one is shown so many times, however, the next one does not appear.
How do I fix this?
you want to use $value['threadcount'] etc. $forum is the array containing all the rows. i wonder that you get some output at all …
fetch_assoc() will only fetch a single row from the resultset. you'd have to use a loop to fill an array:
while(($row = $data->fetch_assoc()) !== FALSE) {
$forum[] = $row;
}
you can then iterate over your $forum array with a foreach loop:
foreach($forum as $row) {
echo htmlspecialchars($row['threadcount']);
// etc.
}
trying to fix this mess …
<?php
$crumbs = explode(",", $user['data']['depts']);
foreach ($crumbs as $crumb) { ?>
<div class="h3top"><?php echo htmlspecialchars($crumb['name']);?></div>
<?
}
$result = $db->query("SELECT * FROM tbl_forums WHERE deptid = " . (int)$id . "");
$forumcount = $result->num_rows;
while(($row = $data->fetch_assoc()) !== FALSE) {
if ($row['lastpost'] == "") { $row['lastpost'] = "--";}
?>
<div class="info2alt">
<div class="info4">
<table width="100%" border="0" cellspacing="1" cellpadding="4">
<tr>
<td width="55%" align="left" valign="middle" class="zebraodd"><?php echo htmlspecialchars($forum['name']); ?></td>
<td width="10%">Threads: <?php echo htmlspecialchars($forum['threadcount']); ?><br />Posts: <?php echo htmlspecialchars($forum['postcount']); ?></td>
<td width="35%">Last Post: <?php echo htmlspecialchars($forum['lastpost']); ?></td>
</tr>
</table>
</div>
<div class="info3bottom"></div>
<?php
}
?>