Your htaccess is kinda hard to read but nothing seems to redirect the user, I think it's your Magento baseurl that does that.
Have you tried adding the following code to the htaccess to redirect to www. on that level?
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
You cannot sort the products by position
field.
This field has meaning only in relation with a category. There is no position
attribute for the product (unless you added one by yourself).
You can get all the data you need with one (not so simple) single select. Here goes:
$res = Mage::getSingleton('core/resource');
$eav = Mage::getModel('eav/config');
$nameattr = $eav->getAttribute('catalog_category', 'name');
$nametable = $res->getTableName('catalog/category') . '_' . $nameattr->getBackendType();
$nameattrid = $nameattr->getAttributeId();
//you could add here to select only the attributes you need but I'm lazy and I added all of them (*)
$collection = Mage::getModel('catalog/product')
->getCollection()->addAttributeToSelect('*');
$collection->joinTable('catalog/category_product',
'product_id=entity_id', array('single_category_id' => 'category_id', 'position_in_category'=>'position'),
null, 'left');
$collection->joinTable(
$nametable,
'entity_id=single_category_id',
array('single_category_name' => 'value'),
"attribute_id=$nameattrid",
'left'
);
$collection->groupByAttribute('entity_id');
$collection->getSelect()
->columns(array('category_ids_values' => new Zend_Db_Expr("IFNULL(GROUP_CONCAT(`catalog_category_product`.`category_id` SEPARATOR ','), '')")))
->columns(array('position_values' => new Zend_Db_Expr("IFNULL(GROUP_CONCAT(`catalog_category_product`.`position` SEPARATOR ','), '')")))
->columns(array('category_names' => new Zend_Db_Expr("IFNULL(GROUP_CONCAT(`{$nametable}`.`value` SEPARATOR ','), '')")));
echo $collection->getSelect();
$final['prodCat_list'] = array();
$i = 0;
foreach ($collection as $product){
$item = array();
$item['sku']= $product->getSku();
$item['product_id']= $product->getId();
$item['name']= $product->getName();
$item['image']=$product->getThumbnailUrl();
$item['description']=$product->getDescription();
$item['short_description']=$product->getShortDescription();
$item['weight']=$product->getWeight();
$item['created_at']=$product->getCreatedAt();
$item['updated_at']=$product->getUpdatedAt();
$item['price']=$product->getPrice();
$item['special_price']=$product->getSpecialPrice();
$item['tax_class_id']=$product->getTaxClassId();
//this can be retrieved directly with $product->getCategoryIds, but they might be in a different order.
$item['cat_id'] = $product->getCategoryIdsValues();
$item['positions'] = $product->getPositionValues();
$item['category_names'] = $product->getCategoryNames();
$final['prodCat_list'][] = $item;
}
This code returns and array with product data. An element looks something like this:
[5] => Array
(
[sku] => MA464LL/A
[product_id] => 25
[name] => Product name here
[image] => image/link here
[description] => Description here.
[short_description] => Short description here
[weight] => 10.6000
[created_at] => 2007-08-24 14:28:50
[updated_at] => 2008-07-28 21:27:34
[price] => 2299.9900
[special_price] =>
[tax_class_id] => 2
[cat_id] => 15,28
[positions] => 0,0
[category_names] => Computers,Laptops
)
Best Answer
A big thank you to the team at ParadoxLabs who helped figure out this issue. I thought I would pass the solution to my problem along incase anyone else should have similar issues.
When we first noticed this issue a few months ago we were updating the categories description. After examining the database, logs, extensions, etc., we started trying various actions in an attempt to trigger the bug (all this was done on a staging site). We observed that only a single category was losing products.
Predictably, saving the 'Fabrics' category (the category that was losing the products) caused exactly the data loss we saw on the live site. Prior to saving there were ~2800 products assigned to the category. We added a word to the category description, clicked the 'Category Products' tab, then saved. After a long load, there were precisely 1001 products assigned to the category. Saving the category again through the same process was very quick and resulted in no further data loss.
Looking at the Magento logs after that, we found this error: "Warning: parse_str(): Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in /app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php on line 310"
Seeing that the max input limit on our server is 1000 and there were 1001 products left after saving, that seems like too much of a coincidence to be ... coincidence.
We've since increased the php 'max_input_vars' value to 5000 or more, which fixed the error.
Thanks to everyone who took the time to help with this!