How to show configurable product stock status? - ajax

I have this phtml file which shows stock status:
<?php $_product = $this->getProduct() ?>
<?php $productQty = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); ?>
<?php if ($productQty > 100): ?>
<div class="catalog-stock over-stock">
<span class="qry-text"><?php echo $this->__('In stock:'); ?></span>
<span class="qry-count">100+</span>
</div>
<?php elseif ($productQty > 0 && $productQty <= 100): ?>
<div class="catalog-stock normal-stock">
<span class="qry-text"><?php echo $this->__('In stock:'); ?></span>
<span class="qry-count"><?php echo $productQty; ?></span>
</div>
<?php elseif ($deliveryDate = $_product->getStockDeliveryDate()): ?>
<div class="catalog-stock no-stock">
<span class="qry-text"><?php echo $this->__('Expected'); ?></span>
<span class="qry-count"><?php echo $deliveryDate; ?></span>
</div>
<?php elseif ($_product->getTypeId() != 'configurable' && $_product->getTypeId() != 'grouped' && $_product->getTypeId() != 'bundle'): ?>
<div class="catalog-stock no-stock">
<span class="qry-text"><?php echo $this->__('Expected'); ?></span>
<span class="qry-count"><?php echo $this->__('n/a'); ?></span>
</div>
<?php endif; ?>
I call it with this line <?php echo $this->getChildHtml('product_type_data') ?> from product/view/view.phtml
When used with simple product it works perfectly, but how to do same thing with configurable product?
What I want is to change stock status depending on what configurations is selected.
One solution is to check if product is configurable and then display all values at same time and hide with css. But if I do this I have problem - how to know which product is selected and show it's stock status?
I guess best option would be to do this with ajax, but I spent hours trying to do that and didn't succeed.

Related

Magento - Let the user choose between exlude tax of include tax

I have a product with multiple options.
The user chooses how much he wants to pay for the product.
First I have created a dropdown box with the values €5,- €10,- etc.
The product price i have put to €0.
When I choose 10 euros, the product changes to 10 euros - that's good.
Now I want a checkbox where users can choose between Exclude Tax and Include Tax, so if I choose excluding tax the product will be inserted in the shopping cart as €10,00 witch is ok (excluding tax).
But when I choose Including tax the product needs to be inserted in the shopping cart as 10 /1.21 = €8,26 (excluding tax).
How can I make this possible?
EDIT:
I have the following code:
$event = $observer->getEvent();
$quote_item = $event->getQuoteItem();
if (is_array($quote_item->getOptions())) {
foreach ($quote_item->getOptions() as $optionValue) {
echo ???? . ' --> ' . $optionValue->getValue() . '<br />';
}
}
This will give me the values from the options.
But how do I get the real option_id? I get the option_type_id now.
If you look to below page
app/design/frontend/default/default/template/catalog/product/price.phtml
you will find below code
<?php if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 0)): // including ?>
<span class="price-excluding-tax">
<span class="label"><?php echo $_taxHelper->__('Excl. Tax:') ?></span>
<span class="price" id="price-excluding-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php echo $_coreHelper->currency($_price+$_weeeTaxAmount,true,false) ?>
</span>
</span>
<span class="price-including-tax">
<span class="label"><?php echo $_taxHelper->__('Incl. Tax:') ?></span>
<span class="price" id="price-including-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php echo $_coreHelper->currency($_finalPriceInclTax+$_weeeTaxAmount,true,false) ?>
</span>
</span>
<?php elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 1)): // incl. + weee ?>
<span class="price-excluding-tax">
<span class="label"><?php echo $_taxHelper->__('Excl. Tax:') ?></span>
<span class="price" id="price-excluding-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php echo $_coreHelper->currency($_price+$_weeeTaxAmount,true,false) ?>
</span>
</span>
to implement you can refer
Changing the price in quote while adding product to cart: magento

Jooma K2 show user description in comments

I really need help this time - Joomla 2.5 and latest K2.
I'm using the default K2 comment system and I want to show the "Description" field for every commenter on that page.
So far I have this code:
$thisUserdata =& JFactory::getUser($comment->userID);
echo $thisUserdata->profile->description;
But this shows the description for the author of the page only.
If I log in with another account, it'll also show my own Description as long as I'm logged in.
All the coding I'm doing is in /components/com_k2/templates/default/item.php
The whole code for comments looks like this:
<?php if($this->item->numOfComments>0 && $this->item->params->get('itemComments') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2'))): ?>
<!-- Item user comments -->
<ul>
<?php foreach ($this->item->comments as $key=>$comment): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; echo (!$this->item->created_by_alias && $comment->userID==$this->item->created_by) ? " author-comment" : ""; echo($comment->published) ? '':' unpublishedComment'; ?>">
<div class="avatar">
<?php if($comment->userImage): ?>
<a href="<?php echo JFilterOutput::cleanText($comment->userLink); ?>" target="_blank" rel="nofollow">
<img src="<?php echo $comment->userImage; ?>" alt="<?php echo JFilterOutput::cleanText($comment->userName); ?>" width="<?php echo $this->item->params->get('commenterImgWidth'); ?>" />
</a>
<?php endif; ?>
</div>
<div class="inner">
<div class="author">
<?php if(!empty($comment->userLink)): ?>
<a href="<?php echo $comment->userLink; ?>" title="View <?php echo $comment->userName; ?> profile" target="_blank" rel="nofollow">
<?php echo $comment->userName; ?>
</a>
<?php else: ?>
<a rel="nofollow"><?php echo $comment->userName; ?></a>
<?php endif; ?>
</div>
<div class="date">
 <?php echo JHTML::_('date', $comment->commentDate, JText::_('K2_DATE_FORMAT_COM_MARIO')); ?>
</div>
<p><?php echo $comment->commentText; ?>
<?php
// USER DESCRIPTION
$thisUserdata =& JFactory::getUser($comment->userID);
echo $thisUserdata->profile->description;
?>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
<div class="itemCommentsPagination">
<?php echo $this->pagination->getPagesLinks(); ?>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php if($this->item->params->get('commentsFormPosition')=='below' && $this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($this->item->catid)))): ?>
<!-- Item comments form -->
<div class="itemCommentsForm">
<?php echo $this->loadTemplate('comments_form'); ?>
</div>
<?php endif; ?>
With Joomla 2.5 you can use that to get basic user information, but you want to use the following to get the "description" or "about me" content of the commenting user..
$commentUser = JUserHelper::getProfile($comment->userID);
print_r($commentUser);
$about_me = $commentUser->profile['aboutme'];
echo $about_me;
Here is the link as well, this might help if you would like to do other things with the JUserHelper..
http://api.joomla.org/Joomla-Platform/User/JUserHelper.html#getProfile
EDIT: Make sure the plugin "User - Profile" is enabled or this will not work.

Magento displays incorrect products in category view

When I load a productcollection in list.phtml for the first time (or when I turn of caching completely) the products that are returned are the products which reside in the category which was created last (i.e. the category with the highest id). When cache is turned on, on page-refresh the correct products are shown. After the cache is deleted, the same situation occurs (for the correct products to show I need to refresh the page once when the productlisting is shown).
One extra strange thing; If I call
$_product->getCategory()->getName()
the correct categoryname is returned, but when
$_product->getName()
is called, the wrong productname returns... Im at a complete loss here. I have read a similar post elsewhere which stated that when cache is turned on, this problem goes away, but only after the first page-refresh which is highly undesirable.
<?php $_coreHelper = $this->helper('core'); ?>
<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getName(); ?>
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); ?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = 4; ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php echo var_dump($_product->getCategory()->getName()); ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid" style="padding-left:0px;">
<?php endif ?>
<li style="height:230px;" class="hreview-aggregate hproduct item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<h2 class="item fn product-name">
<?php echo substr($this->htmlEscape($_product->getName()), 0, 22).'...' ?>
</h2>
<div>
<div>
<img class="photo fn" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(100); ?>" width="100" height="100" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
</div>
<div style="clear:both"></div>
</div>
<div>
<div>
<div>
<div>
<div><span style="font-size:13px;font-weight:bold;"><?php echo $_coreHelper->currency($newprice,true,false) ?> <?php echo $this->helper('tax')->__('Ex. BTW') ?></span></div><br />
<div><?php echo $_coreHelper->currency($newtaxprice,true,false) ?> <?php echo $this->helper('tax')->__('Inc. BTW') ?></div>
</div>
</div>
<div style="clear:both;"></div>
<br />
<form action="<?=$this->getAddToCartUrl($_product);?>" method="post" id="product_addtocart_form_<?=$_product->getId();?>" <?if($_product->getOptions()){?> enctype="multipart/form-data"<?}?>>
<?if(!$_product->isGrouped()){?>
<input type="text" name="qty" id="qty" maxlength="12" value="<?echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1);?>" style="width:30px;" /> x
<?}?>
<button type="button" class="button-order" onclick="this.form.submit()"><span><span><?=$this->__('Bestellen');?></span></span></button>
<br /><br />
<span>Zet in verlanglijst</span>
</form>
</div>
</div>
<div style="clear:both"></div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
Re-Index all your products in re-indexing page.
Clear your cache.
Reload your products page.

Extrafields Visibility. K2 Extension

So i have this code changed in ../html/com_k2/template/default/item.php:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<!-- Item extra fields -->
<div class="itemExtraFields">
<h3><?php echo JText::_('Additional Info:'); ?></h3>
<ul>
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<?php $user =& JFactory::getUser(); ?>
<?php if($extraField->name == "Price" && $user->get('Guest') ==1): ?>
<?php else: ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo ($extraField->type=='date')?JHTML::_('date', $extraField->value, JText::_('K2_DATE_FORMAT_LC')):$extraField->value; ?></span>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<div class="clr"></div>
</div>
<?php endif; ?>
What I'm trying to achieve is to hide the extrafield on Guest Viewer on the front-page, and that extrafield will only be visible to certain User groups. I already tried changing this line three times:
name == "Price" && $user->get('Guest')==1): ?>
name == "itemExtraFields" &&$user->get('Guest')
==1): ?>
name == "itemExtraFieldsValue"
&&$user->get('Guest') ==1): ?>
(I named my custom field as Price)
So i don't know if I'm missing something on the code or i got the itemFields name wrong. Any help would be appreciated a ton. I already asked in the k2 forum and joomla forum but no one is answering.
Try this code. It is working fine.
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<?php if($extraField->name === "Price" && $this->user->guest){}
else{ ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>
<?php }?>
<?php endforeach; ?>
I just added a strict comparison to the name and brackets for the if else condition. Also altered the way of checking guest user.

Magento - Tax Excluded on Product Details Page but Included on Listing Page

My problem is that I don't have the same price in Product Details and Listing Page.
I want to have all over the website the prices Included Tax.
How Can I solve this problem probably of configuration in Magento backend.
Thanks a lot.
for Product List :
look at the following file
root/app/design/frontend/default/default/template/catalog/product/price.phtml
you will see the following code which you can change what you want :
<?php if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 0)): // including ?>
<span class="price-excluding-tax">
<span class="label"><?php echo $_taxHelper->__('Excl. Tax:') ?></span>
<span class="price" id="price-excluding-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php echo $_coreHelper->currency($_price+$_weeeTaxAmount,true,false) ?>
</span>
</span>
<span class="price-including-tax">
<span class="label"><?php echo $_taxHelper->__('Incl. Tax:') ?></span>
<span class="price" id="price-including-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php echo $_coreHelper->currency($_finalPriceInclTax+$_weeeTaxAmount,true,false) ?>
</span>
</span>
<?php elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($_product, 1)): // incl. + weee ?>
<span class="price-excluding-tax">
<span class="label"><?php echo $_taxHelper->__('Excl. Tax:') ?></span>
<span class="price" id="price-excluding-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
<?php echo $_coreHelper->currency($_price+$_weeeTaxAmount,true,false) ?>
</span>
</span>

Resources