Display Child Product SKU in Product Page












1















I am using Magento 2. I would like to display child product SKU in Main product page while user clicks on configurable Swatches.



I am trying to gather information from below file.



public_htmlvendormagentomodule-swatchesviewfrontendtemplatesproductviewrenderer.phtml


like below



<div class="swatch-opt"></div>
<script>
require(["jquery", "jquery/ui", "swatchRenderer"], function ($) {
$('.swatch-opt').SwatchRenderer({
jsonConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonConfig(); ?>,
jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'

});
});

console.log('<?php echo $block->getJsonSwatchConfig(); ?>');
</script>


I am getting below output in console.



{"90":{"12":{"type":"1","value":"#474747","label":"Black"},"13":{"type":"1","value":"#45bcf8","label":"Blue"},"20":{"type":"1","value":"#da859c","label":"Pink"},"21":{"type":"1","value":"#a15ebb","label":"Purple"},"22":{"type":"1","value":"#cb5d4a","label":"Red"}}}


But I could not find SKU there. I would like to get SKU to display that in Main product Page.










share|improve this question
















bumped to the homepage by Community 6 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    1















    I am using Magento 2. I would like to display child product SKU in Main product page while user clicks on configurable Swatches.



    I am trying to gather information from below file.



    public_htmlvendormagentomodule-swatchesviewfrontendtemplatesproductviewrenderer.phtml


    like below



    <div class="swatch-opt"></div>
    <script>
    require(["jquery", "jquery/ui", "swatchRenderer"], function ($) {
    $('.swatch-opt').SwatchRenderer({
    jsonConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonConfig(); ?>,
    jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
    mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'

    });
    });

    console.log('<?php echo $block->getJsonSwatchConfig(); ?>');
    </script>


    I am getting below output in console.



    {"90":{"12":{"type":"1","value":"#474747","label":"Black"},"13":{"type":"1","value":"#45bcf8","label":"Blue"},"20":{"type":"1","value":"#da859c","label":"Pink"},"21":{"type":"1","value":"#a15ebb","label":"Purple"},"22":{"type":"1","value":"#cb5d4a","label":"Red"}}}


    But I could not find SKU there. I would like to get SKU to display that in Main product Page.










    share|improve this question
















    bumped to the homepage by Community 6 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      1












      1








      1








      I am using Magento 2. I would like to display child product SKU in Main product page while user clicks on configurable Swatches.



      I am trying to gather information from below file.



      public_htmlvendormagentomodule-swatchesviewfrontendtemplatesproductviewrenderer.phtml


      like below



      <div class="swatch-opt"></div>
      <script>
      require(["jquery", "jquery/ui", "swatchRenderer"], function ($) {
      $('.swatch-opt').SwatchRenderer({
      jsonConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonConfig(); ?>,
      jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
      mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'

      });
      });

      console.log('<?php echo $block->getJsonSwatchConfig(); ?>');
      </script>


      I am getting below output in console.



      {"90":{"12":{"type":"1","value":"#474747","label":"Black"},"13":{"type":"1","value":"#45bcf8","label":"Blue"},"20":{"type":"1","value":"#da859c","label":"Pink"},"21":{"type":"1","value":"#a15ebb","label":"Purple"},"22":{"type":"1","value":"#cb5d4a","label":"Red"}}}


      But I could not find SKU there. I would like to get SKU to display that in Main product Page.










      share|improve this question
















      I am using Magento 2. I would like to display child product SKU in Main product page while user clicks on configurable Swatches.



      I am trying to gather information from below file.



      public_htmlvendormagentomodule-swatchesviewfrontendtemplatesproductviewrenderer.phtml


      like below



      <div class="swatch-opt"></div>
      <script>
      require(["jquery", "jquery/ui", "swatchRenderer"], function ($) {
      $('.swatch-opt').SwatchRenderer({
      jsonConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonConfig(); ?>,
      jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
      mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'

      });
      });

      console.log('<?php echo $block->getJsonSwatchConfig(); ?>');
      </script>


      I am getting below output in console.



      {"90":{"12":{"type":"1","value":"#474747","label":"Black"},"13":{"type":"1","value":"#45bcf8","label":"Blue"},"20":{"type":"1","value":"#da859c","label":"Pink"},"21":{"type":"1","value":"#a15ebb","label":"Purple"},"22":{"type":"1","value":"#cb5d4a","label":"Red"}}}


      But I could not find SKU there. I would like to get SKU to display that in Main product Page.







      magento2 configurable-product sku






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 5 '18 at 10:29









      Teja Bhagavan Kollepara

      2,94841847




      2,94841847










      asked Aug 16 '16 at 15:25









      abu abuabu abu

      3521622




      3521622





      bumped to the homepage by Community 6 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 6 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          If you use version 2.1.9 and below.
          open file vendor/magento/module-swatches/Helper/Data.php
          find private function getAllSizeImages(ModelProduct $product, $imageFile)
          add:




          'sku' => $product->getSku()




          all function code looke like:



          private function getAllSizeImages(ModelProduct $product, $imageFile) {
          return [
          'large' => $this->imageHelper->init($product, 'product_page_image_large')
          ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
          ->setImageFile($imageFile)
          ->getUrl(),
          'medium' => $this->imageHelper->init($product, 'product_page_image_medium')
          ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
          ->setImageFile($imageFile)
          ->getUrl(),
          'small' => $this->imageHelper->init($product, 'product_page_image_small')
          ->setImageFile($imageFile)
          ->getUrl(),
          'sku' => $product->getSku(),
          ];}


          well be callback SKU.



          more information: https://forum.magentochina.org/t/sku/33






          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%2f131645%2fdisplay-child-product-sku-in-product-page%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














            If you use version 2.1.9 and below.
            open file vendor/magento/module-swatches/Helper/Data.php
            find private function getAllSizeImages(ModelProduct $product, $imageFile)
            add:




            'sku' => $product->getSku()




            all function code looke like:



            private function getAllSizeImages(ModelProduct $product, $imageFile) {
            return [
            'large' => $this->imageHelper->init($product, 'product_page_image_large')
            ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
            ->setImageFile($imageFile)
            ->getUrl(),
            'medium' => $this->imageHelper->init($product, 'product_page_image_medium')
            ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
            ->setImageFile($imageFile)
            ->getUrl(),
            'small' => $this->imageHelper->init($product, 'product_page_image_small')
            ->setImageFile($imageFile)
            ->getUrl(),
            'sku' => $product->getSku(),
            ];}


            well be callback SKU.



            more information: https://forum.magentochina.org/t/sku/33






            share|improve this answer






























              0














              If you use version 2.1.9 and below.
              open file vendor/magento/module-swatches/Helper/Data.php
              find private function getAllSizeImages(ModelProduct $product, $imageFile)
              add:




              'sku' => $product->getSku()




              all function code looke like:



              private function getAllSizeImages(ModelProduct $product, $imageFile) {
              return [
              'large' => $this->imageHelper->init($product, 'product_page_image_large')
              ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
              ->setImageFile($imageFile)
              ->getUrl(),
              'medium' => $this->imageHelper->init($product, 'product_page_image_medium')
              ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
              ->setImageFile($imageFile)
              ->getUrl(),
              'small' => $this->imageHelper->init($product, 'product_page_image_small')
              ->setImageFile($imageFile)
              ->getUrl(),
              'sku' => $product->getSku(),
              ];}


              well be callback SKU.



              more information: https://forum.magentochina.org/t/sku/33






              share|improve this answer




























                0












                0








                0







                If you use version 2.1.9 and below.
                open file vendor/magento/module-swatches/Helper/Data.php
                find private function getAllSizeImages(ModelProduct $product, $imageFile)
                add:




                'sku' => $product->getSku()




                all function code looke like:



                private function getAllSizeImages(ModelProduct $product, $imageFile) {
                return [
                'large' => $this->imageHelper->init($product, 'product_page_image_large')
                ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
                ->setImageFile($imageFile)
                ->getUrl(),
                'medium' => $this->imageHelper->init($product, 'product_page_image_medium')
                ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
                ->setImageFile($imageFile)
                ->getUrl(),
                'small' => $this->imageHelper->init($product, 'product_page_image_small')
                ->setImageFile($imageFile)
                ->getUrl(),
                'sku' => $product->getSku(),
                ];}


                well be callback SKU.



                more information: https://forum.magentochina.org/t/sku/33






                share|improve this answer















                If you use version 2.1.9 and below.
                open file vendor/magento/module-swatches/Helper/Data.php
                find private function getAllSizeImages(ModelProduct $product, $imageFile)
                add:




                'sku' => $product->getSku()




                all function code looke like:



                private function getAllSizeImages(ModelProduct $product, $imageFile) {
                return [
                'large' => $this->imageHelper->init($product, 'product_page_image_large')
                ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
                ->setImageFile($imageFile)
                ->getUrl(),
                'medium' => $this->imageHelper->init($product, 'product_page_image_medium')
                ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
                ->setImageFile($imageFile)
                ->getUrl(),
                'small' => $this->imageHelper->init($product, 'product_page_image_small')
                ->setImageFile($imageFile)
                ->getUrl(),
                'sku' => $product->getSku(),
                ];}


                well be callback SKU.



                more information: https://forum.magentochina.org/t/sku/33







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 5 '18 at 10:33









                Teja Bhagavan Kollepara

                2,94841847




                2,94841847










                answered Nov 10 '17 at 18:05









                shuai zendshuai zend

                1




                1






























                    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%2f131645%2fdisplay-child-product-sku-in-product-page%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

                    What other Star Trek series did the main TNG cast show up in?

                    Berlina muro

                    Berlina aerponto