Magento - No price in product page - magento

I have SCP (simple configurable product) installed and for every simple product that has no custom options, the price doesn’t show up in the product page. As soon as I add an option, the price shows up.
There is no price block or template called on the product page when no options is selected.
I saw that the extension is extending Mage_Catalog_Block_Product_Price block , but I can't find where this block should be called.

Haven't found any solution yet , so I made this jquery workaround that works
Put this at the end of template/catalog/product/view.phtml
jQuery(document).ready(function($) {
if($('.price-box').length==0){
var price = '<div class="price-box"><span class="regular-price"><span class="price">$<?php echo number_format($_product->getPrice(),2); ?></span></span></div>';
$('.product-options-bottom').before(price);
}
});
Of course, you need to have jquery.

Related

WooCommerce ajax add to cart variation

I am using this code to enable ajax add to cart on single product pages. I also have enables ajax in WooCommerce settings in Products tab:
Enable AJAX add to cart buttons on archives
This works well when I am on simple products.
add_action('woocommerce_before_single_product', 'wpv_remove_woocommerce_template_single_add_to_cart');
add_action('woocommerce_before_single_product', 'wpv_add_woocommerce_template_loop_add_to_cart');
function wpv_remove_woocommerce_template_single_add_to_cart(){
global $product;
if ($product->is_type('simple')) {
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
}
}
function wpv_add_woocommerce_template_loop_add_to_cart(){
global $product;
if ($product->is_type('simple')) {
add_action('woocommerce_single_product_summary', 'woocommerce_template_loop_add_to_cart', 30);
}
}
However when I try to use add to cart on variable product I get 400 (Bad Request) ajax error. I cant really see in network panel what to look as reason.
I use default WordPress theme 2022, no other plugins. This only happens when I add this code above, it works without.

Magento get stock quantity at related products, upsells, crosssells in frontend

I need to get the stock quantity for each product in the section where "Related products" is showed in frontend. Using Magento 1.9.
This function will not help me show the actual qty in my related products section:
Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
The function shows stock qty in the product view page and the catalog collection but does not work for related products.
What to do?
I am not sure if you are actually calling the above piece of code inside a PHTML file.
Assuming you are using the RWD theme and calling it inside a PHTML directly (which is not as per Magento Standards), the file location would be app/design/frontend/rwd/default/template/catalog/product/list/related.phtml
Inside, the FOREACH loop, call the below piece of code (screenshot attached for reference - frontend display):
<?php echo Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getQty(); ?>
The ideal solution would be overriding the CORE file:
app/code/core/Mage/CatalogInventory/Model/Stock/Item.php
like below:
app/code/local/Namespace/Modulename/Model/Stock/Item.php
in order to add a new function:
<?php
class Namespace_Modulename_Model_CatalogInventory_Stock_Item extends Mage_CatalogInventory_Model_Stock_Item
{
public function getItemStockQty($product)
{
return $this->loadByProduct($product)->getQty();
}
}
And inside the PHTML file, under the FOREACH LOOP call this function as below:
<?php echo $this->getItemStockQty($_item); ?>
Screenshot
Hope this helps.
Happy Coding...

How to apply coupon in the magento product view before adding product to cart

I had to replicate coupon functionality in which the user can able to apply the coupon code and see the discount price in product page itself before adding that product to cart.
So i used ajax call to load the coupon code , its rule conditions by like the following way
<?php
-----
$oCoupon = Mage::getModel('salesrule/coupon')->load($couponcode, 'code');
if($oCoupon){
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
$rule_arr = unserialize($oRule->getConditionsSerialized());
$actions_serialized = unserialize($oRule->getData("actions_serialized"));
$conditions = $rule_arr['conditions'];
foreach($conditions as $condition){
$conditions1 = $condition['conditions'];
$type = $condition['type'];
foreach($conditions1 as $condition1){
$type = $condition1['type'];
$value = $condition1['value'];
}
}
}
}
----
Here i validated every possible rule - but still its not validating all defined rules and its not stable.
Is there anyway I can able to validate a product and coupon rules - or is there any extension which does validation against one product and coupon rules. Please help me
Since you can apply a code to a cart/quote like this, I would suggest looking in these models for how it actually validates a code on a product. (working backwards)
Mage::getSingleton('checkout/cart')
->getQuote()
->setCouponCode($couponcode)
->collectTotals()
->save();
I suggest to look at this free extension for inspiration :
http://www.magentocommerce.com/magento-connect/estimate-shipping-on-the-product-page.html
It allow showing shipping estimation in product page by simulating an empty cart, adding the product and collecting shipping rate.
What you have to do is simulate the empty cart, add the product, apply the coupon (with Jared Kipe's method) and get the total.
This module will inspire you and give you method to emulate the empty cart.

How to display product on home page category wise which is checked(custom attribute) in magento backend admin

How can we display new products on home page category wise which are selected using custom attribute "Show"(drop down or check box) in magento product list grid or product upload page?
To find product for a particular attribute in category, use the following code:
$id=Mage::app()->getRequest()->getParam('id', false);
$_products=Mage::getModel('catalog/category')->load($id);
$_productcollection=$_products->getProductCollection();
foreach($_productcollection->getAllIds() as $_productid)
{
$_product=Mage::getModel('catalog/product')->load($_productid);
//print $_product->getName().$_product->getShowfront()."<br/>";
$showfnt=$_product->getShowfront();
if($showfnt==1)
{
echo $_product->getname()."<br/>";
/* write here you grid or list code for display product */
}
}
In the above code I created showfront attribute so you write your attribute name there.

Magento Auto Add Items Based on Quantity

I'm designing a custom product page with a button that when clicked I need to have an alert come up with a "Yes" or "No" option.
If "Yes" is selected I then need the following to happen.
Add another product into the cart based on the products quantity i.e. between 1 & 2 items add product A between 3 & 4 Items product B, between 5 & 12 product C and so on.
Any idea of the best way to accomplish this?
It has to be a alert style popup (ajax popup preferred) cannot be a checkbox on the product page.
Thanks!
So I've come across a solution to my problem... I'm using a Simple Modal (That TheBlackBenzKid hinted me to) that I'm either going to call from a custom button or with the add to cart button. This in turn will redirect to a php page that will redirect to the cart. For the php page I'll just include the code to put a item into the cart from there anyone could figure out how to customize it to there own needs.
<?php
// Include Magento application (URL to Mage.php)
require_once ( "app/Mage.php" );
umask(0);
//specified quantity my own variable I'm using for quantities
$spqty = 9;
// Initialize Magento
Mage::app("default");
// You have two options here,
// "frontend" for frontend session or "adminhtml" for admin session
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
// get the current Magento cart
$cart = Mage::getSingleton('checkout/cart');
if ($spqty <= 2) {
// insert item to cart where "98" is the product ID (NOT SKU!) Where "2" is the quantity
$cart->addProduct(98, array('qty' => 2));
} elseif ($spqty >= 4 ){
// you can add multiple products at the same time by adding this line multiple times
$cart->addProduct(96, array('qty' => 3));
}
// save the cart
$cart->save();
// very straightforward, set the cart as updated
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
// redirect to index.php
header("Location: index.php/checkout/cart");
I also found some of this information from this guys blog I'll link to the article
How to add a product from an external site into Magento
I'm happy to answer any questions on this...
This is not the best answer, but code to get you started:
You could make the cart function use:
<input type="button" onClick="javascript:nValidateForm();"/>
And your form code:
<form name="m2mform" id="m2mform" method="post" onSubmit="javascript:nValidateForm();">
And then just call an external JavaScript in your page XML headers and add it to cart so that JS file will always be checked and validate the popup.

Resources