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.
????
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?
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);
Related
I have completely built my website. And I hit a snag when I need to display cart information such as amount of products, total price etc..
My objective right now is to detect when a user is logged in on my prestashop site (Version 1.4). and display any cart information if the user has added any items to the cart. on my other website.
The prestashop site
store.illegear.com
The site I built (full custom code without wordpress or prestashop)
support.illegear.com
I managed to call the cookies following instructions from this website (http://informatique-todo.blogspot.com/2011/10/prestashop-cookie-structure.html). But now I'm trying to understand how to use the cart class from prestashop to get what I want... I don't know the name of the variable nor understand the functions fully to know how to use it.
Note that these webpage exist on the same server and cookies do function. But I don't know how to display what I need from the Prestashop other than creating my own SQLi query functions
include_once('pathtoprestashopdir/config/config.inc.php');include_once('pathtoprestashopdir/settings.inc.php');
include_once('pathtoprestashopdir/classes/Cookie.php');
include_once('pathtoprestashopdir/classes/Cart.php');
global $cookie;
$cookie = new Cookie('ps');
$display = getCustomerCarts($cookie->$id_cart);
echo $display;
Note that all my code displays absolutely nothing while print_r($COOKIE) shows some information such as ID... last logged in... etc..
And yes I flush my cookies and cache. Its empty and I log out. When I log in to my prestashop the cookie data appears on both my prestashop and my secondary site.
Try with :
$display = Cart::getCustomerCarts($cookie->$id_cart);
Regards
I have 1 custom table (not wp core table) where are specific products imported. I've set up custom wp page where these products are listed, custom filter created etc. In this step so far everything is OK - products are listed and filtering works, pagination works...
But what I want to extend further now - open each product page (like /product-listing-page/product-name-1) when clicking on product names in product list page... How can be this achieved "out of wp_posts" table?
Why I'm not using wp_posts table: web site have static pages and dynamic posts as news and product table is truncated and re-imported once in a day every night! So, can not really use wp_posts page when product list is dynamic and totally truncated before each import...
Any ideas? Maybe anybody already did such stuff?;-)
I don't know if you developed a plugin to handle all the custom table and code you created, but if you didn't, I strongly encourage you to do so.
Because by making your code as a plugin, you have the oportunity to use all the composants of wordpress, like the rewrite rules system, which, I think, could help you to achieve your goal.
I created a plugin some times ago for a website I have the charge and I needed a custom page to be displayed within the website (worpdress) url system, which is what you want to do if I correctly understand your question.
Unfortunately the plugin has evolved since and I didn't keep a backup of that code, but if I remember correctly how I did it back when, here is the rough approach I followed:
I create a plugin which handle :
custom db table(s)
custom php objects
...
AND (this is the intersting part) add rewrite rule to wordpress rewrite rules system as follow:
set rewrite tag (init action) (if needed)
add rewrite rule (init action)
intercept url and parse it to get the params i need in my custom
page (parse_request action)
The following functions may help you with that :
add_rewrite_tag
add_rewrite_rule
And you need to hook in :
init
parse_request
Hope it helps you start.
the solution was quite quick and easy! For my needs it was enough just to register global query var:
function register_new_query_var($vars) {
$vars[] = 'product_id';
return $vars;
add_filter('query_vars', 'register_new_query_var');
and then I changed theme template for page product-listing-page to work for product listing and individual products with using
if(!get_query_var('product_id')). So, if query empty - do listing stuff, if not empty - do individual product stuff!
For me this is quite enough and I do not need even seo friendly urls (because product list changes every day, so - every day will be new products, links, and there will be to much 404 errors)...
and I can use http://example.com/product-listing-page?product_id=1 and page displays with date which is from custom table! ;-)
I am currently using OpenCart 1.5. I need to display the product purchased in the orders page inside the admin: sales/order. along with the Order_id, customer, status, total, etc...
Should I be able to do this with a module? or can I modify the model (order.php) with another database query. Currently it is called getOrders($data = array()) but it only queries the .order_status database so therefore I can't return the product's name as part of the foreach results in the controller nor the view. Although line 562 in the same model looks pretty familiar to what I want but it is only used after an action is clicked on by the user.
Any help?
You have two choices:
either You make Your edits using the vQmod XML file, while the original code stays intouched
or You make Your edits in the code directly (which may cause problems if You'd decide to upgrade in the future)
Anyway, a module won't do that (unless You think of vQmod edits as a module). You would need to edit the controller - getList() method and the model - getOrders() method. Think wisely how much information You want to display, as products may have other options and You may end up in a juggernaut query and only the list of 20 orders may take few seconds to complete...
Good luck.
I have two products and their type is "Grouped Product" now I want to change this products in to simple product. Is there any way to do so?
Some links says I have to change directly from database. I tried this but nothing changes. Is there any way to do it?
If it's only 2 maybe you should just create 2 new products with same url and change the url of the old ones.
Alternatively you could do some programming.
Maybe start with this class Mage_Catalog_Model_Product_Type_Grouped.
the public function getAssociatedProducts returns an array of associated products which you can simply sort through applying whatever logic before creating your new products.
You have to deal with store scope etc during this process but there's lots of tutorials.
product type cannot be changed in admin!
may be you could go "catalog_product_entity" table and change the type_id from grouped to simple, but i dunno whether it induced new error, but one thing i only know is you must lost the grouped item linkage.
Have you rebuilt the indices (Admin / System / Index Management) and refreshed the cache (Admin / System / Cache Management)?
Maintaining a Magento site built by someone else, noticed the site owner had not populated Meta Title, Description & Keywords on a product level. The default meta-information for the site populates into every product page.
After successfully populating these attributes for the store view, clearing cache, re-indexing, verifying the attributes are active, etc., the default meta-information for the site is still what populates the product page.
Seems like it would be a configuration issue, but at this point I'd like to rule out the chance that the original developer altered the core functionality somehow. I see where the getTitle() method populates the default meta-information when it can't find something more specific, so that's cool and it's doing so because there is no data for the title when it's rendering the page.
Where would I find the method that creates/populates data for the product object when building a product page?
If I find where that happens, I should be able to test for what is coming out of the database directly.
Or, if by reading this you realize I've missed checking a config option, would love to hear about that, too.
The product meta titles are set in Mage_Catalog_Block_Product_View in the _prepareLayout() method
See here