Magento doesn't show all the categories in admin - magento

we have a magento store with various categories one inside another (subcategory). Our problem is that when we enter in the admin to manage categories in the category tree on the left, some of our categories that has subcategories looks correctly with the plus (+) icon on the left but when we try to expand the category magento doesn't display any item.
The ajax call point to this url:
index.php/admin/catalog_category/categoriesJson/key/09b218741dce69171825fdbf4954855d/?isAjax=true
and it returns an empty array without throwing any error. Frontend displays all the categories correctly.
Magento version 1.4.2.1
Any idea ?

you want to go into table catalog_category_entity
run the following SQL query:
UPDATE catalog_category_entity SET children_count =
(SELECT COUNT(*) FROM
(SELECT * FROM catalog_category_entity) AS table2
WHERE path LIKE
CONCAT(catalog_category_entity.path,"/%"));

After reading Joseph answer i've tried to search for errors in catalog_category_entity and founded that all the categories in my tree has level 1 or 2 except for the categories that doesn't appear that have level 7. The strange things is that level 7 is the correct level for those category anyway i think that the problem is that Magento found a category with level 2 and it direct children has lavel 7 and it doesn't recognize those category as children for the father category.
I've changed level of the children to 2 and everything seems to work.
Why all the category in my tree has level 1 ? i don't know ...

Did you create the categories programmatically (as opposed to using the admin interface)? As is often the case in Magento, when some value is missing or incorrect in the database, entries may not show up at all. If this is the case, please take a look at a "good" category record in the database and make sure that the missing categories follow the correct conventions.
Hope that helps!
Thanks,
Joe

In my case I imported all of the categories and assigned 'level' as its position in the tree. Maybe that isn't what it's for, because setting all the categories to a level of 2 worked beautifully and kept my tree intact.
Code I used to put all levels to 2 after setting it incorrectly:
foreach ($categories as $category) {
$category = $category->load($category->getId());
$level = $category->getLevel();
if($level > 2) {
$category->setLevel(2);
$category->save();
}
}

For the mentioned cases, this query could have helped:
select c.entity_id cid, p.entity_id pid
from
catalog_category_entity c
inner join catalog_category_entity p on c.parent_id = p.entity_id
where c.level != p.level+1
It didn't help me with my categories, though.

Related

I have categories and product table. i want to show the categories which has at least 1 product in Laravel

I have categories and product table. i want to show the categories which has at least 1 product
First you have to make one to many relationship it`s described there: https://laravel.com/docs/8.x/eloquent-relationships#one-to-many
And then you can call and check if it has products
Use has.
$categories = Category::has('products')->get();
This will return all categories that have at least one product.

Magento Backend > Product Attributes showing less attributes that it should

When in backend I can't see all custom attributes. Same occurs in frontend.
I selected EAV_ATTRIBUTE table and can see 179 product attributes (type = 4).
But backend Product > Attributes shows only 119.
Anyone know what could be happening?
Magento Version: 1.7.0.2
IN the admin grid for attributes, the attribute collection is retrieved like this:
$collection = Mage::getResourceModel('catalog/product_attribute_collection')
->addVisibleFilter();
So not all the attributes that exist are listed in there. Only the ones marked as is_visible in the catalog_eav_attribute table.
Try this select and see what you get.
SELECT
*
FROM
eav_attribute e
LEFT JOIN `catalog_eav_attribute` ce
ON e.attribute_id = ce.attribute_id
WHERE
e.entity_type_id = 4 AND
ce.is_visible = 1
This should get you the attributes that are listed in the admin grid.
Perhaps the database has inconsistent data due to use of direct SQL insert statements or such. Its logical that only the consistent data would show up.
I've seen some import scripts which could lead to such inconsistencies floating around on the 'net.
Maybe you got bitten by one?

Magento - How to clean up attributes not in attribute set

I am taking over a website from another developer, and have found the setup of attributes to be a bit of a mess.
Specifically, products have attributes that aren't associated with the relevant attribute sets.
If you take wine with an attribute set "Wines", one of whose attributes is "Grape Variety".
But I also have "Beers" with a completely different attribute set, but somehow one of my beers has a Grape Variety.
It's not assigned to the Beers attribute set, it doesn't show up in the back end for this product, (so I can't edit it) but if I look in the database it's there (in catalog_product_entity_* and catalog_product_index_eav), furthermore when I do an export it's there too, and if someone searches for "Merlot", they are coming up with this beer. There are hundreds of products like this.
What is the best way of removing all attributes from products that are not within their assigned attribute sets?
I could figure it out in SQL I'm sure, but that's not the best way of doing things as I'd be afraid of missing something and screwing up the products altogether.
This is what I ended up doing. A few weeks later and it doesn't seem to have caused any issues yet:
CREATE TABLE catalog_product_entity_int_old LIKE catalog_product_entity_int;
INSERT INTO catalog_product_entity_int_old SELECT * FROM catalog_product_entity_int;
DELETE FROM catalog_product_entity_int
WHERE value_id IN
(SELECT cpei.value_id
FROM catalog_product_entity_int_old cpei
WHERE cpei.attribute_id NOT IN
(SELECT eea.attribute_id
FROM eav_entity_attribute eea
JOIN catalog_product_entity cpe ON eea.attribute_set_id = cpe.attribute_set_id
WHERE cpe.entity_id = cpei.entity_id)
ORDER BY cpei.entity_id)
and
DELETE FROM catalog_product_index_eav WHERE
attribute_id NOT IN (
(SELECT eea.attribute_id
FROM eav_entity_attribute eea
JOIN catalog_product_entity cpe ON eea.attribute_set_id = cpe.attribute_set_id
WHERE cpe.entity_id = catalog_product_index_eav .entity_id)
);
Then regenerate the indices.
I would definitely use Magmi to clean this up:
First, do a product export from within Magento (System -> Import/Export -> Profiles) and choose "Export All Products." In the resulting CSV, you will have columns for each attribute and you can remove any irrelevant attribute values for each product. This will allow you to bypass the backend where attributes are set for a particular product, but not in the product's attribute set.
Take a good look at the Magmi Wiki, but a few quick tips: Magmi only imports the columns you specify, so you can safely remove most of the columns when you perform your import. For example, I always make sure to remove the image columns if I'm not importing images (or you may lose all of your images). Also, be sure to do a database backup before running your import in case something goes wrong.

Creating a page to show data with foreign keys

I'm creating an APEX application that allows students to apply to job placements, and allows an admin to see all interactions. I want to create a page to show all of the students applications.
First off, here's the database schema for the tables involved:
Full sized link: http://i.stack.imgur.com/QU1Pr.png
I have a report with a list of students and I've added a "View Applications" column. I've made the "View Applications" column linkable, and it goes to the new page. The problem is, I have no idea how to show all of the applications for the student that the admin is currently looking up.
The only way I can think of doing it is passing RECORD_NUMBER (PK in students table) to the new page and then executing some SQL using that, and populating the page fields with what's returned. But I have no idea how to do that. I don't know how to grab the RECORD_NUMBER value to use in SQL and I don't know how to populate form fields with what's returned by the SQL.
Any help is appreciated.
So you've got one page that lists applications and the students that have applied. We'll call that page 1. If I understand what you're trying to do, you can create a page 2, with a report and a hidden page item. Call the page item P2_RECORD_NUMBER.
Create the report with the query:
SELECT *
FROM tbl_jobs j
INNER JOIN tbl_applications a on a.job_id = j.id
INNER JOIN tbl_students s ON s.record_number = j.record_number
WHERE s.record_number = :P2_RECORD_NUMBER
Now edit the link on page 1 so it points to page 2 and populates P2_RECORD_NUMBER with the record_number of the row that the user clicked on. I don't have Apex in front of me, but I think you can do that by editing the report attributes for that column. Also, you can use the url of the form http://site.com/f?p=<APP_ID>:<PAGE_ID>:0::::P2_RECORD_NUMBER:<record_number>. (I'm doing that from memory and may have the number of colons wrong.)
You'll also want to have some default text in place in case the query above returns no rows.
Just create a new page for the admin and enter a query like
SELECT *
FROM tbl_students s
JOIN tbl_applications a USING (record_number)
JOIN tbl_jobs j ON a.job_id = j.id
Do you know where to add the query?

ActiveRecord Join that gets first associated product photo

I'm using ActiveRecord inside CodeIgniter to interact with a MySQL database.
I have a product table and a product_photo table that stores associated photos for products along with a sort_order for each product_photo.
I am attempting to select the first product photo (lowest sort_order) but can't seem to make it work.
I've boiled it down to selecting the product_photo and joining the product to it (I tried the opposite initially) but I always end up with the first product_photo for the first test product and second product_photo for the second test product.
To simplify further, I tried selecting just the product_photo records, sorting them by product_id and sort_order, and then spitting that out and I still end up with mis-matched results.
Here's my ActiveRecord query:
$this->db->select('product_id, url, sort_order')
->from('product_photo')
->order_by('product_id, sort_order')
->group_by('product_id');
I'm sure there is a better approach to this, but I haven't found it yet. Thanks in advance for any insight.
Can't you use DISTINCT 1? Also, you should be selecting from the product table, and Use a left join to select the corresponding photo.

Resources