0

when i access to stores product my new attribute i found this : enter image description here

ok this is my code to install the new attribute

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{

    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

    $eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY,'choix_prix_product');
    $eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'choix_prix_product',/* Custom Attribute Code */
        [
            'type' => 'text',/* Data type in which formate your value save in database*/
            'backend' => '',
            'frontend' => '',
            'label' => 'Choix-Prix de vente', /* lablel of your attribute*/
            'input' => 'select',
            'class' => '',
            'source' => 'Mdweb\ConfigAttribute\Model\Config\Source\Options',
            /* Source of your select type custom attribute options*/
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
            /*Scope of your attribute */
            'visible' => true,
            'required' => false,
            'user_defined' => false,
            'default' => '',
            'searchable' => false,
            'filterable' => false,
            'comparable' => false,
            'visible_on_front' => false,
            'used_in_product_listing' => false,
            'unique' => false
        ]
    );
}

}

and this is the source code :

 public function getAllOptions()
{

    $_product = $this->registry->registry('current_product');

    $_sku = $_product->getSku();
    if (isset($_sku)){

    $var1 = substr($_sku, 0, 1);


    $var2 = substr($_sku, 1, 2);

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
    $connection = $resource->getConnection();
    $tableName = $resource->getTableName('table_prix');


    $fields = array('prix_unitaire');


    $sql = $connection->select()
        ->from($tableName, $fields)
        ->where('code_famille' . '=?', $var1)
        ->where('code_nom_commercial' . '=?', $var2)
        ->join('table_choix',
            'table_choix.choix_id = table_prix.code_choix',
            [
                'designation_choix'
            ]);

    $result = $connection->fetchAll($sql);

    if ($result) {
        $i = 0;
        foreach ($result as $elt) {
            $this->_options[$i] = ['label' => " Choix" . $elt['designation_choix'] . "-" . $elt['prix_unitaire'] . "£", 'value' => " Choix" . $elt['designation_choix'] . "-" . $elt['prix_unitaire'] . "£"];
            $i++;
        }


    }   }else{
        $this->_options = [
            ['label' => __(''), 'value' =>'' ]];

    }


    return  $this->_options;


}

the idea is to create a product then return to this product and make it configurable according to the options of the new attribute if there is no options so my product is simple i can see my new product enter image description here

but when i access the attribute details i find the screenshot that i put in first time I waited to find my new attribute like others so what's the problem any help please

34

Your Answer

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

Browse other questions tagged or ask your own question.