I am am trying to configure a magento store . I have a couple of ghost products that appear on the Front end. These Ghost products have no name, no image , and aren't found under my back-end product list. However their add to button is active and works and also has a wishlist URL in the form of.
example.com/wishlist/index/add/product/4/form_key/p3jZL1nym3j4XeNl/
I think I got myself into this mess after trying to duplicate a few products. How do I trace and get rid of these ghost products. Im using absolute template.
Do you using the flat tables? If yes then try to reindex it.
P.S. check the product ID: 4 (in the backend).
If you wanna delete products with blank(null) product name & images
You can try
$products=Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*')->load();
foreach($products as $key => $pId)
{
$product=Mage::getModel('catalog/product')->load($pId);
if($product->getName()=='' && $product->getMediaGalleryImages()=='')
{
$product = Mage::getModel('catalog/product')->load($pId)->delete();
echo "successfully deleted product with ID: ". $pId ."<br />";
}
else{ echo "Could not delete product with ID: ". $pId ."<br />"; }
}
You can also try deleting products which dont have imgs using
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->getSelect()
->joinLeft(
array('_gallery_table' => $collection->getTable('catalog/product_attribute_media_gallery')),
'e.entity_id = _gallery_table.entity_id',
array()
)
->where('_gallery_table.value IS NULL');
$collection->delete();
Related
I was assigned a Magento 1.9.3 project that would take in products in JSON format, and save customer group prices. However, even though there are no errors, nothing gets saved. The group prices won't show in the admin panel nor in the catalogue as expected.
Why is this? I've looked up every single article or stackexchange cases concerning group prices, but none of these seem to solve my problem.
Currently using the catalog_block_product_list_collection event.
$group_prices = $theProduct->getData('group_price');
if (is_null($group_prices)) {
$attribute = $theProduct->getResource()->getAttribute('group_price');
if ($attribute) {
$attribute->getBackend()->afterLoad($theProduct);
$group_prices = $theProduct->getData('group_price');
}
}
if(!is_array($group_prices)){
$group_prices = array();
$theProduct->addData(array('group_price' => $group_prices));
$theProduct->save();
}
$new_price = array(array (
'website_id'=>Mage_Core_Model_App::ADMIN_STORE_ID,
'customer_group_id'=>$customerGroupId,
'price'=> $singleProduct->Price));
$group_prices = array_merge($group_prices, $new_price);
$currentStore = Mage::app()->getStore()->getId();
try{
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
// First Delete all the group prices of product
$theProduct->setData('group_price', array());
$theProduct->save();
// Again save the old prices and new prices
$theProduct->setData('group_price', $group_prices);
$theProduct->save();
} catch(Exception $e) {
echo $e->getMessage();
}
Mage::app()->getStore()->setId($currentStore);
And yet, no group prices are saved when checking in the admin panel. Any help is appreciated.
For customer group field use cust_group instead of customer_group_id.
$new_price = array(array (
'website_id'=>Mage_Core_Model_App::ADMIN_STORE_ID,
'cust_group'=>$customerGroupId,
'price'=> $singleProduct->Price));
For details see:
app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Groupprice/Abstract.php line 299
there is condition:
if ($hasEmptyData || !isset($data['cust_group']) || !empty($data['delete'])) {
continue;}
In app/code/local/Mage/Catalog/Product/Type/Configurable/Price.php, I am trying to get the attribute values of an associated product within the wishlist. I've attempted several approaches but I can only seem to produce data for the parent product.
Latest attempt
$customer = Mage::getSingleton('customer/session')->getCustomer();
if($customer->getId()) {
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true);
$wishListItemCollection = $wishlist->getItemCollection();
foreach ($wishListItemCollection as $wlitem) {
$wishitem = Mage::getModel('catalog/product')->setStoreId($wlitem->getStoreId())->load($wlitem->getProductId());
//echo $wishitem->getId() . '<br>';
if($product->getId() == $wishitem->getId()) { //if the current product id equals the wishlist product id
echo $wishitem->getSku()."</br>";
}
}
}
That only gets me the parent product's sku. What I ultimately want to get is the attribute value for 2 attributes that I added for configurable products (not super attributes) but it seems that $product in Price.php only has the parent product collection.
Other Attempts:
$item_s = Mage::getModel('wishlist/item')->loadWithOptions($product->getId(), 'simple_product')->getOptionsByCode();
$simple_product = $item_s['simple_product']->getData();
$simple_product_id = $simple_product['product_id'];
$sim_product = Mage::getModel('catalog/product')->load($simple_product_id);
print_r($sim_product);
This only resulted in an error on the page.
Also:
$_item = Mage::getModel('catalog/product')->load($product->getId());
//echo $_item->getData('ppuom');
//print_r($_item);
$simpleProduct = $_item->getOptionsByCode()['simple_product']->getItem()->getProduct();
print_r($simpleProduct);
Seems as if you were most of the way there. I've tested this on my Magento site and it worked for me. It's pretty simple actually, you just have to grab the right model for that collection. Also, it seems like you're changing the pricing?!?! Be careful that your wishlist items contain the necessary attributes used in your logic.
$_item = Mage::getModel('catalog/product')->load($product->getId());
$attribute1 = $_item->getData('attribute1_code'); //see admin for attribute code
$attribute2 = $_item->getData('attribute2_code'); //see admin for attribute code
OR
Make changes to your template's wishlist files rather than the pricing logic in the code folder. You'll have access to all the data you need and it won't interfere with the price.php file which is relied on heavily in the cart and other critical areas of the website. The price in the wishlist is recalculated when it's moved to the cart anyway.
As above, I've got a strange issue where every other product I add isn't added to the cart or quote in Magento.
It's repeatable, in that I can add one product, then the next one doesn't add (but I do get a status messaging saying it was added), and then the next done after that adds as it should do.
It's not specific to a product, as if I add the same product a second time it will add as expected.
The only thing we have that's a little different is an observer called on the sales_quote_add_item event, but that's just changing the pricing:
public function update_book_price(Varien_Event_Observer $observer) {
//get the admin session
Mage::getSingleton('core/session', array('name'=>'adminhtml'));
if (!$quoteitem = $observer->getQuoteItem()){
$quoteitem = $observer->getItem();
}
if (!$item = $observer->getEvent()->getQuoteItem()){
$item = $quoteitem;
}
$quote = $item->getQuote();
$product = $item->getProduct();
$price = Mage::helper('users')->getCustomerProductPrice(false,Mage::getModel('catalog/product')->load($product['product_id']),false,true,$_POST['qtys'][$product['product_id']]);
echo "Price : $price \n";
//print_r($price);
$price = $price;
if(!$quoteitem->setOriginalCustomPrice($price)) {
echo "Couldn't set price";
}
else {
echo "price updated, save";
try {
$quoteitem->getProduct()->setIsSuperMode(true);
var_dump($quoteitem->save());
}catch(Exception $e){
echo $e->getMessage() . "\n";
}
}
return $this;
}
I've checked at a DB level, and the missing items are not even in the DB - sales_flat_quote_item has no record of them, but the 'working' items are in as normal.
Has anyone experienced anything like this before, or can anyone suggest where I might start investigating? Thanks!
You don't have to save quote item after changing price.
Delete var_dump($quoteitem->save()); and try again.
I tried to update product's attribute called barcode as follows.
It update the product but cleared tier price of that product. Please help me.
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $prod_sku);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
if ($product) {
$product->setBarcode($bar_code);
$product->save();
}
if(! $product->save()){
makes little sense as the ! is telling if NOT TRUE product must have been saved....but a successfull saved product is returning $this which is seen as true for the IF-clause without the expression mark.
I guess your problem is completely related to another technical problem...
EDIT: There seems to be some weird problem have a look at this...sounds strange but give it a try Magento product tier prices are deleted on product images update
I got an answer from Marius for my question in magento statckoverflow. Thanks Marius.I'm going to add it here for reference.
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$id = Mage::getModel('catalog/product')->getIdBySku($prod_sku);
$product = Mage::getModel('catalog/product')->load($id);
if ($product) {
$product->setBarcode($bar_code);
if(! $product->save()){
$productId = $product->getId();
echo "product_Id :: ".$productId." - Product sku :: ".$product->getSku()."<br />";
}else{
echo "not saved";
}
}
I am trying to update some (but not all ) prices from one store to another. For example one line of shirts should be 1.2 times the price in the second store
I would like to update some groups of items only, based on entity label but am struggling to pull all the data from magento (asside what i can get out in the code below). The bits I am missing are price and entity label. I know what tables they live in but not sure the correct magento syntax to access them eg Mage::getModel('catalog/product') and I am trying to achieve this using Magento friendly code and not queries
Using enterprise 1.11, not looking at buying a plugin at this stage, any advice greatly appreciated
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); #important
$product_id = '8782';
$collection = Mage::getModel('catalog/product')
->load($product_id);
echo "Collection: " . $collection->getName();
echo "<br>";
echo "Attribute Set: " . $collection->getAttributeSetId() . " SKU: " . $collection->getSku();
echo "<br>";
echo "Entity ID: " . $collection->getEntity_id() . " Product Type (Attribute Label): " . $collection->getProducttype();
Just clarifying:
In the sample you've shown, the $collection object isn't really a "collection".
It's an instance of one 'catalog/product' object.
To modify the price of one catalog/product object, you'd be looking at doing something like this:
$product = Mage::getModel('catalog/product')->load($product_id);
$product->setPrice($product->getPrice() * 1.2)
->save();
If you want to do this over a bunch of products, you'll probably want to use a collection of
'catalog/product' objects, and apply some attribute filters (which boils down to adding
WHERE clauses to the eventually generated SQL). (Here's one summary of the magento collection query
syntax.)
I'm not sure what you mean by "entity label". Is that a custom attribute you've attached to your products?
A general example, applying this price change to all products with a certain SKU:
$product_collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('sku', array('like' => 'FOO01-%'));
foreach($product_collection as $product) {
$new_price = calcNewPrice($product->getPrice());
$product->setPrice($new_price)
->save();
}
Where, if you're going across stores for price calcs, "calcNewPrice" might look something like this:
function calcNewPrice($product) {
$other_store_product = Mage::getModel('catalog/product')->setStoreId($other_store_id)
->load($product->getId());
if ($other_store_product) {
return $other_store_product->getPrice() * 1.2;
}
// else ???
}
Hope this helps.