How to get parent group Product ID from getParentIdsByChild() method of MagentoGroupedProductModelProductTypeGrouped? The Next CEO of Stack OverflowOptimal structure of grouped products with more than 30K unique productsAdd new product type for grouped productChange product type from grouped to configurableProduct type for me? Grouped bundle?Link Grouped Parent/Children With Default Quantity setMagento2 cannot override class MagentoGroupedProductModelProductTypeGrouped?How to get Image of Parent product for grouped child product in a template?get Product not work - Magento 2Magento 2 : Wrong Count of Shop By on Search Result Page If there is Grouped ProductHow to redirect simple products to the parent grouped product?

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

How do I solve this limit?

Whats the best way to handle refactoring a big file?

What is the difference between "behavior" and "behaviour"?

Describing a person. What needs to be mentioned?

What is the purpose of the Evocation wizard's Potent Cantrip feature?

How to make a variable always equal to the result of some calculations?

What makes a siege story/plot interesting?

How to be diplomatic in refusing to write code that breaches the privacy of our users

How to write the block matrix in LaTex?

Can I equip Skullclamp on a creature I am sacrificing?

How long to clear the 'suck zone' of a turbofan after start is initiated?

Why does C# sound extremely flat when saxophone is tuned to G?

How do scammers retract money, while you can’t?

Opposite of a diet

Why do remote companies require working in the US?

Why doesn't a table tennis ball float on the surface? How do we calculate buoyancy here?

Is it safe to use c_str() on a temporary string?

Anatomically Correct Mesopelagic Aves

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Why is there a PLL in CPU?

Is a stroke of luck acceptable after a series of unfavorable events?

Fastest way to shutdown Ubuntu Mate 18.10

Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables



How to get parent group Product ID from getParentIdsByChild() method of MagentoGroupedProductModelProductTypeGrouped?



The Next CEO of Stack OverflowOptimal structure of grouped products with more than 30K unique productsAdd new product type for grouped productChange product type from grouped to configurableProduct type for me? Grouped bundle?Link Grouped Parent/Children With Default Quantity setMagento2 cannot override class MagentoGroupedProductModelProductTypeGrouped?How to get Image of Parent product for grouped child product in a template?get Product not work - Magento 2Magento 2 : Wrong Count of Shop By on Search Result Page If there is Grouped ProductHow to redirect simple products to the parent grouped product?










0















Currently, I am having an issue with retrieving group parent product_id using PHP external script wich file resides under /pub directory:



<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('memory_limit', '5G');
error_reporting(E_ALL);
use MagentoFrameworkAppBootstrap;
require '../app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();

$productRepository =
$objectManager->get('MagentoCatalogModelProductRepository');

$typeGroup = $objectManager->get('MagentoGroupedProductModelProductTypeGrouped');

//child product_id
$simple_child_associated_to_group_product_id = 13884;
$product = $productRepository->getById($simple_child_associated_to_group_product_id);

//this returns the
//row_id of the parent not the product_id
$groupParentIds = $typeGroup->getParentIdsByChild($product->getId());


//shortens the array by one element and store it to a variable
$groupParentId = array_shift($groupParentIds);

//display group parent id
echo $groupParentId;



You can confirm the echoed value is the row_id value of
getParentIdsByChild() using this query in your M2 Database:




SELECT * FROM `catalog_product_entity` WHERE `row_id` = 'put $groupParentId value here'



Take note of the entity_id:23526




enter image description here
To confirm that the returned value of $groupParentId is truly the parent product of the child simple... you can confirm this by:




log-in to your admin panel, go to catalog > products, then search the parent product via ID filter with value of 23526
enter image description here



click the row to open the product info. and check the associated simple products in the Grouped Products section.











share|improve this question






















  • did you try var_dump($groupParentIds) ?

    – Mohit chauhan
    yesterday











  • @Mohitchauhan yes sir I tried and it returns the row_id of a product. I checked the native Magento 2 getParentIdsByChild() method equivalent SQL query: SELECT catalog_product_link.product_id, catalog_product_link.linked_product_id FROM catalog_product_link WHERE (linked_product_id IN('13884')) AND (link_type_id = 3) and confirmed that the product_id column of the catalog_product_link table is equivalent to the row id of the catalog_product_entity

    – Eubie Aluad
    yesterday












  • So this row_id is actually product_id of group product. now what else you want here ?

    – Mohit chauhan
    yesterday











  • @Mohitchauhan I basically wanted to retrieve the entity_id or product_id of a product given that I already have it's row_id. I already tried loading the product using product repository getById(row_id) however it returns me incorrect data. The product repository expects the id to be entity_id or product_id of a product.

    – Eubie Aluad
    yesterday












  • Didn't get you. you already have product_id as row_id.

    – Mohit chauhan
    yesterday















0















Currently, I am having an issue with retrieving group parent product_id using PHP external script wich file resides under /pub directory:



<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('memory_limit', '5G');
error_reporting(E_ALL);
use MagentoFrameworkAppBootstrap;
require '../app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();

$productRepository =
$objectManager->get('MagentoCatalogModelProductRepository');

$typeGroup = $objectManager->get('MagentoGroupedProductModelProductTypeGrouped');

//child product_id
$simple_child_associated_to_group_product_id = 13884;
$product = $productRepository->getById($simple_child_associated_to_group_product_id);

//this returns the
//row_id of the parent not the product_id
$groupParentIds = $typeGroup->getParentIdsByChild($product->getId());


//shortens the array by one element and store it to a variable
$groupParentId = array_shift($groupParentIds);

//display group parent id
echo $groupParentId;



You can confirm the echoed value is the row_id value of
getParentIdsByChild() using this query in your M2 Database:




SELECT * FROM `catalog_product_entity` WHERE `row_id` = 'put $groupParentId value here'



Take note of the entity_id:23526




enter image description here
To confirm that the returned value of $groupParentId is truly the parent product of the child simple... you can confirm this by:




log-in to your admin panel, go to catalog > products, then search the parent product via ID filter with value of 23526
enter image description here



click the row to open the product info. and check the associated simple products in the Grouped Products section.











share|improve this question






















  • did you try var_dump($groupParentIds) ?

    – Mohit chauhan
    yesterday











  • @Mohitchauhan yes sir I tried and it returns the row_id of a product. I checked the native Magento 2 getParentIdsByChild() method equivalent SQL query: SELECT catalog_product_link.product_id, catalog_product_link.linked_product_id FROM catalog_product_link WHERE (linked_product_id IN('13884')) AND (link_type_id = 3) and confirmed that the product_id column of the catalog_product_link table is equivalent to the row id of the catalog_product_entity

    – Eubie Aluad
    yesterday












  • So this row_id is actually product_id of group product. now what else you want here ?

    – Mohit chauhan
    yesterday











  • @Mohitchauhan I basically wanted to retrieve the entity_id or product_id of a product given that I already have it's row_id. I already tried loading the product using product repository getById(row_id) however it returns me incorrect data. The product repository expects the id to be entity_id or product_id of a product.

    – Eubie Aluad
    yesterday












  • Didn't get you. you already have product_id as row_id.

    – Mohit chauhan
    yesterday













0












0








0








Currently, I am having an issue with retrieving group parent product_id using PHP external script wich file resides under /pub directory:



<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('memory_limit', '5G');
error_reporting(E_ALL);
use MagentoFrameworkAppBootstrap;
require '../app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();

$productRepository =
$objectManager->get('MagentoCatalogModelProductRepository');

$typeGroup = $objectManager->get('MagentoGroupedProductModelProductTypeGrouped');

//child product_id
$simple_child_associated_to_group_product_id = 13884;
$product = $productRepository->getById($simple_child_associated_to_group_product_id);

//this returns the
//row_id of the parent not the product_id
$groupParentIds = $typeGroup->getParentIdsByChild($product->getId());


//shortens the array by one element and store it to a variable
$groupParentId = array_shift($groupParentIds);

//display group parent id
echo $groupParentId;



You can confirm the echoed value is the row_id value of
getParentIdsByChild() using this query in your M2 Database:




SELECT * FROM `catalog_product_entity` WHERE `row_id` = 'put $groupParentId value here'



Take note of the entity_id:23526




enter image description here
To confirm that the returned value of $groupParentId is truly the parent product of the child simple... you can confirm this by:




log-in to your admin panel, go to catalog > products, then search the parent product via ID filter with value of 23526
enter image description here



click the row to open the product info. and check the associated simple products in the Grouped Products section.











share|improve this question














Currently, I am having an issue with retrieving group parent product_id using PHP external script wich file resides under /pub directory:



<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('memory_limit', '5G');
error_reporting(E_ALL);
use MagentoFrameworkAppBootstrap;
require '../app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$objectManager = MagentoFrameworkAppObjectManager::getInstance();

$productRepository =
$objectManager->get('MagentoCatalogModelProductRepository');

$typeGroup = $objectManager->get('MagentoGroupedProductModelProductTypeGrouped');

//child product_id
$simple_child_associated_to_group_product_id = 13884;
$product = $productRepository->getById($simple_child_associated_to_group_product_id);

//this returns the
//row_id of the parent not the product_id
$groupParentIds = $typeGroup->getParentIdsByChild($product->getId());


//shortens the array by one element and store it to a variable
$groupParentId = array_shift($groupParentIds);

//display group parent id
echo $groupParentId;



You can confirm the echoed value is the row_id value of
getParentIdsByChild() using this query in your M2 Database:




SELECT * FROM `catalog_product_entity` WHERE `row_id` = 'put $groupParentId value here'



Take note of the entity_id:23526




enter image description here
To confirm that the returned value of $groupParentId is truly the parent product of the child simple... you can confirm this by:




log-in to your admin panel, go to catalog > products, then search the parent product via ID filter with value of 23526
enter image description here



click the row to open the product info. and check the associated simple products in the Grouped Products section.








magento2 grouped-products






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









Eubie AluadEubie Aluad

7711




7711












  • did you try var_dump($groupParentIds) ?

    – Mohit chauhan
    yesterday











  • @Mohitchauhan yes sir I tried and it returns the row_id of a product. I checked the native Magento 2 getParentIdsByChild() method equivalent SQL query: SELECT catalog_product_link.product_id, catalog_product_link.linked_product_id FROM catalog_product_link WHERE (linked_product_id IN('13884')) AND (link_type_id = 3) and confirmed that the product_id column of the catalog_product_link table is equivalent to the row id of the catalog_product_entity

    – Eubie Aluad
    yesterday












  • So this row_id is actually product_id of group product. now what else you want here ?

    – Mohit chauhan
    yesterday











  • @Mohitchauhan I basically wanted to retrieve the entity_id or product_id of a product given that I already have it's row_id. I already tried loading the product using product repository getById(row_id) however it returns me incorrect data. The product repository expects the id to be entity_id or product_id of a product.

    – Eubie Aluad
    yesterday












  • Didn't get you. you already have product_id as row_id.

    – Mohit chauhan
    yesterday

















  • did you try var_dump($groupParentIds) ?

    – Mohit chauhan
    yesterday











  • @Mohitchauhan yes sir I tried and it returns the row_id of a product. I checked the native Magento 2 getParentIdsByChild() method equivalent SQL query: SELECT catalog_product_link.product_id, catalog_product_link.linked_product_id FROM catalog_product_link WHERE (linked_product_id IN('13884')) AND (link_type_id = 3) and confirmed that the product_id column of the catalog_product_link table is equivalent to the row id of the catalog_product_entity

    – Eubie Aluad
    yesterday












  • So this row_id is actually product_id of group product. now what else you want here ?

    – Mohit chauhan
    yesterday











  • @Mohitchauhan I basically wanted to retrieve the entity_id or product_id of a product given that I already have it's row_id. I already tried loading the product using product repository getById(row_id) however it returns me incorrect data. The product repository expects the id to be entity_id or product_id of a product.

    – Eubie Aluad
    yesterday












  • Didn't get you. you already have product_id as row_id.

    – Mohit chauhan
    yesterday
















did you try var_dump($groupParentIds) ?

– Mohit chauhan
yesterday





did you try var_dump($groupParentIds) ?

– Mohit chauhan
yesterday













@Mohitchauhan yes sir I tried and it returns the row_id of a product. I checked the native Magento 2 getParentIdsByChild() method equivalent SQL query: SELECT catalog_product_link.product_id, catalog_product_link.linked_product_id FROM catalog_product_link WHERE (linked_product_id IN('13884')) AND (link_type_id = 3) and confirmed that the product_id column of the catalog_product_link table is equivalent to the row id of the catalog_product_entity

– Eubie Aluad
yesterday






@Mohitchauhan yes sir I tried and it returns the row_id of a product. I checked the native Magento 2 getParentIdsByChild() method equivalent SQL query: SELECT catalog_product_link.product_id, catalog_product_link.linked_product_id FROM catalog_product_link WHERE (linked_product_id IN('13884')) AND (link_type_id = 3) and confirmed that the product_id column of the catalog_product_link table is equivalent to the row id of the catalog_product_entity

– Eubie Aluad
yesterday














So this row_id is actually product_id of group product. now what else you want here ?

– Mohit chauhan
yesterday





So this row_id is actually product_id of group product. now what else you want here ?

– Mohit chauhan
yesterday













@Mohitchauhan I basically wanted to retrieve the entity_id or product_id of a product given that I already have it's row_id. I already tried loading the product using product repository getById(row_id) however it returns me incorrect data. The product repository expects the id to be entity_id or product_id of a product.

– Eubie Aluad
yesterday






@Mohitchauhan I basically wanted to retrieve the entity_id or product_id of a product given that I already have it's row_id. I already tried loading the product using product repository getById(row_id) however it returns me incorrect data. The product repository expects the id to be entity_id or product_id of a product.

– Eubie Aluad
yesterday














Didn't get you. you already have product_id as row_id.

– Mohit chauhan
yesterday





Didn't get you. you already have product_id as row_id.

– Mohit chauhan
yesterday










1 Answer
1






active

oldest

votes


















0














@Mhitchauhan answered my question by using this line of codes in my PHP external script file:



$objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager 
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('catalog_product_entity'); //gives table name with prefix
//Select Data from table
$sql = "Select * FROM " . $tableName ." where row_id='$row_id'";
$result = $connection->fetchAll($sql);
var_dump($result);





share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267585%2fhow-to-get-parent-group-product-id-from-getparentidsbychild-method-of-magento%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    @Mhitchauhan answered my question by using this line of codes in my PHP external script file:



    $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager 
    $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
    $connection = $resource->getConnection();
    $tableName = $resource->getTableName('catalog_product_entity'); //gives table name with prefix
    //Select Data from table
    $sql = "Select * FROM " . $tableName ." where row_id='$row_id'";
    $result = $connection->fetchAll($sql);
    var_dump($result);





    share|improve this answer





























      0














      @Mhitchauhan answered my question by using this line of codes in my PHP external script file:



      $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager 
      $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
      $connection = $resource->getConnection();
      $tableName = $resource->getTableName('catalog_product_entity'); //gives table name with prefix
      //Select Data from table
      $sql = "Select * FROM " . $tableName ." where row_id='$row_id'";
      $result = $connection->fetchAll($sql);
      var_dump($result);





      share|improve this answer



























        0












        0








        0







        @Mhitchauhan answered my question by using this line of codes in my PHP external script file:



        $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager 
        $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
        $connection = $resource->getConnection();
        $tableName = $resource->getTableName('catalog_product_entity'); //gives table name with prefix
        //Select Data from table
        $sql = "Select * FROM " . $tableName ." where row_id='$row_id'";
        $result = $connection->fetchAll($sql);
        var_dump($result);





        share|improve this answer















        @Mhitchauhan answered my question by using this line of codes in my PHP external script file:



        $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager 
        $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
        $connection = $resource->getConnection();
        $tableName = $resource->getTableName('catalog_product_entity'); //gives table name with prefix
        //Select Data from table
        $sql = "Select * FROM " . $tableName ." where row_id='$row_id'";
        $result = $connection->fetchAll($sql);
        var_dump($result);






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited yesterday









        Ghulam.M

        17811




        17811










        answered yesterday









        Eubie AluadEubie Aluad

        7711




        7711



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267585%2fhow-to-get-parent-group-product-id-from-getparentidsbychild-method-of-magento%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Sum ergo cogito? 1 nng

            419 nièngy_Soadمي 19bal1.5o_g

            Queiggey Chernihivv 9NnOo i Zw X QqKk LpB