0

I'm trying to get a custom attribute (mgs_brand) in MagePlaza's One Step Checkout.

I've created a catalog_attributes.xml file like so -

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd">
    <group name="quote_item">
        <attribute name="mgs_brand"/>
    </group>
</config>

Added this code to my details.js -

getBrand: function (parent) {
                console.log("details.js starts here");
                var itemProduct = this.getItemProduct(parent.item_id);
                return itemProduct.mgs_brand;
},

Added this to my details.html -

<!-- ko if: (getBrand($parent))-->
       <strong class="product-item-brand" data-bind="text:getBrand($parent)"></strong>
<!-- /ko -->

The closest I've managed to get is a value in the window.checkoutConfig object, but it's an ID rather than the actual attribute value.

Am I missing a step here?

1 Answer 1

0

Have you tried adding your value in CompositeConfigProvider

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <type name="Magento\Checkout\Model\CompositeConfigProvider">
       <arguments>
           <argument name="configProviders" xsi:type="array">
               <item name="mgs_brand" xsi:type="object">Namespace\ModuleName\Model\AdditionalConfigVars</item>
           </argument>
       </arguments>
   </type>
</config>

/app/code/Namespace/Modulename/Model/AdditionalConfigVars.php

<?php

namespace Namespace\Modulename\Model;

use \Magento\Checkout\Model\ConfigProviderInterface

class AdditionalConfigVars implements ConfigProviderInterface
{
   public function getConfig()
   {
       $additionalVariables['mgs_brand'] = 'Test Var';
       return $additionalVariables;
   }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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