0

I'm looking for an explaination about column "Position" in table "Catalog_Category_Product".
I dont understand what is 0 and 1 in that column, and what does it for? Thanks for reading. Have a good day :)

EDIT 1:

Maybe i'm not clear enough when asking the question, so...
I'm trying to do "banner_slider" follow the structure of "catalog_category_product"

C:\xampp\htdocs\magento\vendor\magento\module-catalog\Block\Adminhtml\Category\AssignProducts.php

So in that code, i debug with xdebug phpstorm and realize that position="1" show in "yes", but in the database it have position="0" as well. I dont know what it does .. That's what i'm wondering
Here is what i debug:

public function getProductsJson()
{
    $products = $this->getCategory()->getProductsPosition();
    if (!empty($products)) {
        return $this->jsonEncoder->encode($products);
    }
    return '{}';
}

enter image description here

enter image description here


After running that code, they render throught this in "getProductsJson()" function:

C:\xampp\htdocs\magento\vendor\magento\module-catalog\view\adminhtml\templates\catalog\category\edit\assign_products.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var \Magento\Catalog\Block\Adminhtml\Category\AssignProducts $block */

/** @var \Magento\Catalog\Block\Adminhtml\Category\Tab\Product $blockGrid */
$blockGrid = $block->getBlockGrid();
$gridJsObjectName = $blockGrid->getJsObjectName();
?>
<?= $block->getGridHtml() ?>
<input type="hidden" name="category_products" id="in_category_products" data-form-part="category_form" value="" />
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Catalog/catalog/category/assign-products": {
                "selectedProducts": <?= /* @escapeNotVerified */ $block->getProductsJson() ?>,
                "gridJsObjectName": <?= /* @escapeNotVerified */ '"' . $gridJsObjectName . '"' ?: '{}' ?>
            }
        }
    }
</script>
<!-- @todo remove when "UI components" will support such initialization -->
<script>
    require('mage/apply/main').apply();
</script>
  • Accept answer which is really useful for you. – Suresh Chikani Aug 9 '18 at 11:42
3

Category products display based on set position. You can check product position in admin >> Catalog >> Categories >> Select any category >> Product In Category.

You can check below reference screenshots, admin and front.

Admin : enter image description here

Front : enter image description here

  • Sorry for late reply. Hmm .. okay, so i already know this, i'm trying to do "banner_slider" follow this structure of "category_product" (which you are showing to me). So in that code, i debug with xdebug phpstorm and realize that position="1" show in "yes", but in the database it have position="0" as well. I dont know what it does .. that what i'm wondering. – fudu Aug 10 '18 at 1:28
  • I've edited the post, please check :) – fudu Aug 10 '18 at 1:45
2

You can sort products inside a category. Just go the backend, edit a category's product list - you will find the field "position" there; insert any number, not only "0" and "1" are possible.

Position is also the default sorting for categories in Magento. You can change that in the backend in Shops > Configuration > Catalog.

This is an answer that can easily be solved by googling, so please do this next time before you ask something here.

  • Sorry for late reply. Hmm .. okay, so i already know this, i'm trying to do "banner_slider" follow this structure of "category_product" (which you are showing to me). So in that code, i debug with xdebug phpstorm and realize that position="1" show in "yes", but in the database it have position="0" as well. I dont know what it does .. that what i'm wondering. – fudu Aug 10 '18 at 1:32
  • I've edited the post, please check :) – fudu Aug 10 '18 at 1:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.