product show in stock in admin order when it is in out of stock Magento - magento

Hi i am trapped in a very strange situation, my client has enable the customers to order the products which are out of stock , the problem is when the customer place the order it shows the product in stock in order . I need to show the product status out of stock in the order so he come to know about the order item status .
Below is the settings i have in catalog-> inventory in admin
please suggest me where i am doing mistake or how can i do this
thanks

You need to modify your product.phtml inside app/design/frontend/{yourpackage}/{yourtheme}/template/catalog/product/view.phtml
Add following in your code scope for testing and checking if its not already showing out of stock .
$stockItem = Mage::getModel('cataloginventory/stock_item');
$resource = $stockItem->loadByProduct($_product->getId());
if(round($resource->getQty(),0) < 1)
{
echo "product is out of stock";
}
The above code actually tests if there is any quantity available in stock and is greater than 1. Also make a note that this will not work for the products setup as not to be managed by stock under inventory tab in product add/modify case.
Thanks

Related

Magento Product Stock status changes automatically

We are facing a issue in Magento 2.4. We are using MSI and we have 3 warehouses. All products have assigned 3 warehouse and we manage stock using MSI. A product can be available on one warehouse and can't be available on another, The issue is when we get product out of stock one day it get automatically in stock after 1 or 2 days and its random behavior not with specific products or warehouse.
Initially we thought may be its done by someone in team if they worked on same product so we have setup an alert when ever product get changed by admin we get notification on Email. But the strange thing is without any alert still status get changed.
I have used this event controller_action_catalog_product_save_entity_after to trigger an alert when ever product get changed and its working as well we have tested it.
Although we have restrict import functionality for other users, but we think product may be changed through csv or api although we have restricted but may be it can be done from any user.
Can any one please help if someone faced similar issue or any model function which always trigger when ever product stock status get changed from any action like API or from CSV or from Admin Edit or even frontend ??
I believe you can use Magento event catalog_product_save_after. Create an observer method that does the following on event catalog_product_save_after.
public function catalog_product_save_after($observer) {
$product = $observer->getProduct();
$stockData = $product->getStockData();
if ( $product && $stockData['qty'] ) {
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getEntityId()); // Load the stock for this product
$stock->setData('is_in_stock', 1); // Set the Product to InStock
$stock->save(); // Save
}
}

How to divide all prices by lets say 3 for a Customer Group in Magento

I am currently showing retail prices in Magento.
I would like to show different prices for wholesale customer group and I would like to divide all prices by 3 to show for logged in users that are in the wholesale customer group.
Any ideas?
You can simply add price customer group wise for each products from magento backend
Go to product >> price tab
you will see Group Price option select your group in your case add price for wholesale group then add your other price for general users.
Ok here is how I did it.
I found this extension Price factor http://www.magentocommerce.com/magento-connect/price-factor.html which multiplies the price with any number you specify.
Then from the extension file /app/code/community/Psquared/PriceFactor/Model/Observer.php
I added some code
$customer = $observer->getEvent()->getCustomer();
//$customer_group_id=$customer->getCustomerGroupId();
$customer_group_id = Mage::getSingleton('customer/session')->getCustomerGroupId();
if ($customer_group_id!=2)
{
// code of the default if statements
}

Magento - Updating the price of a configurable product option

Magento version 1.6.1.0. I'm attempting to write some code that will dynamically update the price of a configurable product's option. My ultimate aim is to write a module that will update the price of the configurable product's options based on the price of the children products of the configurable. The attached code pulls out all the configurable products from a catalogue and displays them along with the product options & prices and the children products' name & price. I plan to work out the difference in price between the configurable and each child product and update the price appropriate option to match. So far I have been unable to work out how to update the price of a product option.
Short version: I just need a way to update the price of a configurable product's option. Do you know how to do this?
<?php
require_once './app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(1);
// load in configurable products
$productConfig = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', 'configurable');
foreach ($productConfig as $_product)
{
// load the configurable product
$_product = Mage::getModel('catalog/product')->load($_product->getId());
echo 'Product Name';
var_dump ($_product->getName());
var_dump ($_product->getPrice());
// Collect options applicable to the configurable product
$productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
$attributeOptions = array();
foreach ($productAttributeOptions as $productAttribute)
{
var_dump($productAttribute['label']);
foreach ($productAttribute['values'] as $attribute)
{
var_dump($attribute);
}
}
// loop through the child products
echo 'Child products';
$col = Mage::getModel('catalog/product_type_configurable')->setProduct($_product)->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
foreach($col as $simple_product)
{
var_dump($simple_product->getName());
var_dump($simple_product->getPrice());
}
}
echo '~fin';
?>
Thank you!
Well, I solved this one after quite a bit of head scratching. I don't know if I did it "right" or not.
I solved it by manually running some SQL to adjust the pricing in the catalog_product_super_attribute_pricing table. If you're going to do this, you'll need a product_super_attribute_id, which you can get from the catalog_product_super_attribute table if you have a product ID.
One caveat: If a price does not exist in the backend for an option (if the option exists, but adds £0 to the product price when selected), there will not be a record for the option in the catalog_product_super_attribute_pricing table, you'll need an insert query instead of an update in that case.
I had the same issue and I started doing the same thing: write a module to update configurable product's options.
I recently published it here: Magento Configurable Auto Pricing
I tested it just with EE 1.12 but it should work also with CE and I'd be glad if anyone wants to try it and give me any feedback or even better write his own fixes and commit them :)

Some products not showing up in magento backend but exist

When am trying to search a product by sku for example "abc123" in backend then magento not gives any result but when am trying to find this in Global Record Search then magento give me a record of this product. I don't understand that actually where this product exist and from where i can found in backend?
and probably this product was added by quick product creation.
Please go to the product configuration page and go to the inventory and set particular product qty as you want and select stock availability as "in stock"
I hope you solve your problem instantly.

How can get Final Price, with applied price rule in Magento

For example
$_producte = Mage::getModel('catalog/product')->load(2974);
echo $_producte->getFinalPrice();
I can get in frontend when insert to .phtml
BUT I can not get final price (with discount) in admin section or in custom product export file.
Price calculation in Magento is a hot mess. You need to load the frontend event area in order to trigger rule calculation (ref Mage_CatalogRule_Model_Observer::processFrontFinalPrice() configured in Mage_CatalogRule config.xml).
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_FRONTEND,Mage_Core_Model_App_Area::PART_EVENTS);
I think its not necessary to load the frontend event area part. Often the product is not instanced correctly.
Try:
$product
->setStoreId(1) //your store_id here
->setCustomerGroupId(1) //your favorite customer group id here
->load($productId)
and then:
$product->getFinalPrice()
should give the correct final price.
Otherwise try the solutions given here:
https://stackoverflow.com/a/14096072/2787671

Resources