Question

I created a script to store articles in magento from external sources.

This is what I'm currently doing

    $this->product = Mage::getModel('catalog/product')->loadByAttribute('sku',$this->artnr);
    Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
    if($this->product===false || $this->product->getId()<1){
        $this->product = Mage::getModel('catalog/product');
        $this->product->setSku($this->actindo['art_nr']);
        $this->newProduct = true;
        $this->product->setAttributeSetId($this->getDefaultAttributeSetId());
        $this->product->setStoreId(Mage::app()->getStore()->getWebsiteId());
        $this->product->setCreatedAt(strtotime('now'));
    }

Then I set all the required fields like description etc

and then I'm doing a store

$this->product->save();

The Products appear correctly in the Admin Backend, but they aren't visible in the shop frontend.

I checked the database and saw that several indexes are not written. Also the flat tables aren't saved. If I store it afterwards again in the admin backend, everything is saved. I have the flat tables currently disabled. But their content is still written.

I'm using Magento 1.7.0.1 with PHP5.3 runing as fpm and web server nginx.

I also already tried to rebuild the indexes and everything, but it still is not visible in the frontend. What am I doing wrong? All fields that I push to the script get written and are visible in the admin section. ????

Was it helpful?

Solution

you have probably tried all these but I know figuring out 'why is the product not showing' is a frustrating process.

My advice is try making a similar product manually in the Magento admin area and then check all the fields in the admin area for each product. You might look at setting 'website_ids' closely and I think store_id and website_id are different things, no? $store_id = Mage::app()->getStore()->getStoreId(); vs $store_website_id = Mage::app()->getStore()->getWebsiteId();

You could also use the system->import/export export tool to compare what Magento has set vs what your algorithm is setting.

Are you reading the Magento AdminHTML functions for product saving?

    /* path:  app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php */
    Mage_Adminhtml_Catalog_ProductController::saveAction()
    // (and then obviously)
    Mage_Adminhtml_Catalog_ProductController::_initProductSave()
    Mage_Adminhtml_Catalog_ProductController::_initProduct()

So looking at that code, if you can capture the POST from the Magento Admin when you click the save button when you manually make your test product then you will be able to see what is being 'passed in' to the saveAction() function and compare that with your code.

Where do you run your code from? If you are instantiating your own Mage::app() I think you need to set it up as an admin session and set store ids and such. I can't find a reference to that but search around if you think that might be something to do with it. Maybe you can use a call to saveAction() or re-purpose that code rather than using $this->product->save().

If you have a test module for running arbitrary code, try some debug calls and echos from building different product collections to see what is the difference between your generated product and your manually entered test product.

Plan B : If you have an external product data source, you might find the most excellent 'MAGMI Datapump API' the simplest and quickest way to achieve what you want.

Was that too much information?

OTHER TIPS

There are some settings that are required in order to have a product on the frontend.
It must be enabled:

->setStatus(1);

It must be visible

->setVisibility(4); //or 2

It must be in stock or you must have the setting to display out of stock products on frontend.

$stockItem = array();
$stockItem['qty'] = 100; //something bbigger than 0
$stockItem['is_in_stock'] = 1;
$product->setData('stock_item', $stockItem);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top