magento2.3 – How to add Product Attribute Values from Custom Model Data

I’m building a module for Supplier Inventory.

I created a UI Component for creating Suppliers in the dashboard.

In my ModelData I added the Supplier Name.

    class Supplier extends AbstractExtensibleObject implements SupplierInterface
    {
    /**
     * Get supplier_id
     *
     * @return string|null
     */
    public function getSupplierId()
    {
        return $this->_get(self::SUPPLIER_ID);
    }

    /**
     * Set supplier_id
     *
     * @param string $supplierId
     *
     * @return SupplierInterface
     */
    public function setSupplierId($supplierId)
    {
        return $this->setData(self::SUPPLIER_ID, $supplierId);
    }

    /**
     * Get supplier_name
     *
     * @return string|null
     */
    public function getSupplierName()
    {
        return $this->_get(self::SUPPLIER_NAME);
    }

    /**
     * Set supplier_name
     *
     * @param string $supplierName
     *
     * @return SupplierInterface
     */
    public function setSupplierName($supplierName)
    {
        return $this->setData(self::SUPPLIER_NAME, $supplierName);
    }

    /**
     * Retrieve existing extension attributes object or create a new one.
     *
     * @return VendorModuleApiDataSupplierExtensionInterface|null
     */
    public function getExtensionAttributes()
    {
        return $this->_getExtensionAttributes();
    }

    /**
     * Set an extension attributes object.
     *
     * @param VendorModuleApiDataSupplierExtensionInterface $extensionAttributes
     *
     * @return $this
     */
    public function setExtensionAttributes($extensionAttributes)
    {
        return $this->_setExtensionAttributes($extensionAttributes);
    }

    /**
     * Get supplier_shipping_days
     *
     * @return string|null
     */
    public function getSupplierShippingDays()
    {
        return $this->_get(self::SUPPLIER_SHIPPING_DAYS);
    }

    /**
     * Set supplier_shipping_days
     *
     * @param string $supplierShippingDays
     *
     * @return SupplierInterface
     */
    public function setSupplierShippingDays($supplierShippingDays)
    {
        return $this->setData(self::SUPPLIER_SHIPPING_DAYS, $supplierShippingDays);
    }

    /**
     * Get supplier_feed_url
     *
     * @return string|null
     */
    public function getSupplierFeedUrl()
    {
        return $this->_get(self::SUPPLIER_FEED_URL);
    }

    /**
     * Set supplier_feed_url
     *
     * @param string $supplierFeedUrl
     *
     * @return SupplierInterface
     */
    public function setSupplierFeedUrl($supplierFeedUrl)
    {
        return $this->setData(self::SUPPLIER_FEED_URL, $supplierFeedUrl);
    }

    /**
     * Get supplier_feed_separator
     *
     * @return string|null
     */
    public function getSupplierFeedSeparator()
    {
        return $this->_get(self::SUPPLIER_FEED_SEPARATOR);
    }

    /**
     * Set supplier_feed_separator
     *
     * @param string $supplierFeedSeparator
     *
     * @return SupplierInterface
     */
    public function setSupplierFeedSeparator($supplierFeedSeparator)
    {
        return $this->setData(self::SUPPLIER_FEED_SEPARATOR, $supplierFeedSeparator);
    }

    /**
     * Get supplier_feed_sku_field
     *
     * @return string|null
     */
    public function getSupplierFeedSkuField()
    {
        return $this->_get(self::SUPPLIER_FEED_SKU_FIELD);
    }

    /**
     * Set supplier_feed_sku_field
     *
     * @param string $supplierFeedSkuField
     *
     * @return SupplierInterface
     */
    public function setSupplierFeedSkuField($supplierFeedSkuField)
    {
        return $this->setData(self::SUPPLIER_FEED_SKU_FIELD, $supplierFeedSkuField);
    }

    /**
     * Get supplier_feed_stock_field
     *
     * @return string|null
     */
    public function getSupplierFeedStockField()
    {
        return $this->_get(self::SUPPLIER_FEED_STOCK_FIELD);
    }

    /**
     * Set supplier_feed_min_stock_field
     *
     * @param string $supplierFeedStockField
     *
     * @return SupplierInterface
     */
    public function setSupplierFeedStockField($supplierFeedStockField)
    {
        return $this->setData(self::SUPPLIER_FEED_STOCK_FIELD, $supplierFeedStockField);
    }

    /**
     * Get supplier_feed_min_stock
     *
     * @return string|null
     */
    public function getSupplierFeedMinStock()
    {
        return $this->_get(self::SUPPLIER_FEED_MIN_STOCK);
    }

    /**
     * Set supplier_feed_min_stock
     *
     * @param string $supplierFeedMinStock
     *
     * @return SupplierInterface
     */
    public function setSupplierFeedMinStock($supplierFeedMinStock)
    {
        return $this->setData(self::SUPPLIER_FEED_MIN_STOCK, $supplierFeedMinStock);
    }
}

I also add a Product attribute supplier through the VendorModuleSetupPatchDataAddSupplierProductAttribute.php

class AddSupplierProductAttribute implements DataPatchInterface, PatchRevertableInterface
{
    /**
     * @var ModuleDataSetupInterface
     */
    private $moduleDataSetup;

    /**
     * @var EavSetupFactory
     */
    private $eavSetupFactory;

    /**
     * Constructor
     *
     * @param ModuleDataSetupInterface $moduleDataSetup
     * @param EavSetupFactory          $eavSetupFactory
     */
    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup,
        EavSetupFactory $eavSetupFactory
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->eavSetupFactory = $eavSetupFactory;
    }

    /**
     * @return AddSupplierProductAttribute|void
     */
    public function apply()
    {
        $this->moduleDataSetup->getConnection()->startSetup();
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(('setup' => $this->moduleDataSetup));
        $eavSetup->addAttribute(
            MagentoCatalogModelProduct::ENTITY,
            'supplier',
            (
                'type' => 'int',
                'label' => 'Supplier',
                'input' => 'select',
                'source' => VendorModuleModelProductAttributeSourceSupplier::class,
                'frontend' => '',
                'required' => false,
                'backend' => '',
                'sort_order' => '30',
                'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
                'default' => null,
                'visible' => true,
                'user_defined' => true,
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => false,
                'unique' => false,
                'apply_to' => '',
                'group' => 'General',
                'used_in_product_listing' => false,
                'is_used_in_grid' => true,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'option' => ''
            )
        );

        $this->moduleDataSetup->getConnection()->endSetup();
    }

    /**
     * @return void
     */
    public function revert()
    {
        $this->moduleDataSetup->getConnection()->startSetup();
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(('setup' => $this->moduleDataSetup));
        $eavSetup->removeAttribute(MagentoCatalogModelProduct::ENTITY, 'supplier');

        $this->moduleDataSetup->getConnection()->endSetup();
    }

    /**
     * @return array
     */
    public function getAliases()
    {
        return ();
    }

    /**
     * @return array
     */
    public static function getDependencies()
    {
        return ();
    }
}

I was wondering how I can add the Supplier Name that is created through the UI Component will automatically add a value to the Product Attribute Supplier.

ajax – I want to run checking code on Ubercart product attribute

I want to run checking code on a Ubercart product field attribute before allowed to proceed with the checkout. The code could run right below or in conjunction with the “required” – not empty – check.

But looking at the attributes module I do not see where it runs from. Trying to use the Ubercart Field Attributes module to do this on the fly with Ajax and JQuery my code is running without syntax error but also the form_set_error is not working as I am trying to use an Ajax callback.

No message comes up on the product form.

Both the attributes and field attributes work to throw the errors if the fields are empty as should be, but if I knew where the “required” error could originate I could piggyback my code there for this singular product class item

The Ubercart forums pages seem to be down

Can anyone point me to where that “required” checkbox code is in the attributes system ??

magento2 – How to create my custom visual swatch color attribute in my own module Vendor/Module/Setup/Patch/Data/MyOwnColorAttribute?

I take from https://github.com/magento/magento2/blob/2.3/dev/tests/integration/testsuite/Magento/Swatches/_files/product_visual_swatch_attribute.php like example, but my own color attribute patch didn’t create any options if I add those parameters. This is my code:

<?php 
namespace VendorModuleSetupPatchData;

use MagentoCatalogModelProduct;
use MagentoEavModelEntityAttributeScopedAttributeInterface;
use MagentoEavModelEntityAttributeSourceTable;
use MagentoEavSetupEavSetupFactory;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupPatchDataPatchInterface;
use VendorModuleModelAttributeBackendColor as Backend;
use VendorModuleModelAttributeFrontendColor as Frontend;

class AddColorAttribute implements DataPatchInterface
{
    /**
     * @var ModuleDataSetupInterface
     */
    private $moduleDataSetup;

    /**
     * @var EavSetupFactory
     */
    private $eavSetupFactory;

    /**
     * @param ModuleDataSetupInterface $moduleDataSetup
     * @param EavSetupFactory $eavSetupFactory
     */
    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup,
        EavSetupFactory $eavSetupFactory,
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->eavSetupFactory = $eavSetupFactory;
    }

    /**
     * @inheritdoc
     */
    public function apply()
    {
        $this->moduleDataSetup->startSetup();
        $eavSetup = $this->eavSetupFactory->create();
        $eavSetup->addAttribute(Product::ENTITY, 'visual_swatch_color_attribute', (
            'type' => 'int',
            'label' => 'Visual Swatch Color Attribute',
            'input' => 'select',
            'frontend' => Frontend::class,
            'backend' => Backend::class,
            'source' => Table::class,
            'required' => false,
            'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
            'visible' => true,
            'is_used_in_grid' => true,
            'is_visible_in_grid' => true,
            'is_filterable_in_grid' => true,
            'user_defined' => true,
            'searchable' => true,
            'filterable' => true,
            'comparable' => true,
            'visible_on_front' => true,
            'used_in_product_listing' => true,
            'is_html_alowed_on_front' => true,
            'unique' => false,
            'swatch_input_type' => 'visual',
            'swatchvisual' => (
                'value' => (
                    'Obsidian' => '#3a322d',
                    'Pure' => '#0000ff',
                    'Crimson' => '#dc143c',
                    'Emerald' => '#50c878',
                    'Ametyst' => '#9966cc',
                ),
            ),
            'optionvisual' => (
                'values' => (
                    'Obsidian' => ('Obsidian'),
                    'Pure' => ('Pure'),
                    'Crimson' => ('Crimson'),
                    'Emerald' => ('Emerald'),
                    'Ametyst' => ('Ametyst'),
                ),
            ),
            'default' => '1'
        ));

        $eavSetup->addAttributeToGroup(
            MagentoCatalogModelProduct::ENTITY,
            'Default',
            'Product Details',
            'visual_swatch_color_attribute',
            18
        );
        $this->moduleDataSetup->endSetup();
    }

    /**
     * @inheritdoc
     */
    public static function getDependencies(): array
    {
        return ();
    }

    /**
     * @inheritdoc
     */
    public function getAliases(): array
    {
        return ();
    }
}

Can I reset the `[DisallowMultipleComponent]` attribute in child classes in Unity somehow?

Can I reset the (DisallowMultipleComponent) attribute in child classes in Unity somehow?

I want to create my base class:

(DisallowMultipleComponent)
public class MyCompanyClass : Monobehaviour {}

I want all my component scripts to inherit from the MyCompanyClass. So, I will be able to add only one instance of my component script to a game object at a time. I need it for most of my classes. But for some classes I still want to preserve the ability to add a few class instances to a game object, while still inheriting from the MyCompanyClass (because I am going to put some custom behavior into it, which is going to be used by all my component scripts).

So, I was trying to search for something like (AllowMultipleComponent), but found nothing. Is there maybe another way to achieve what I want?

Magento2: How to get attribute EAN and implement to search URL

I have simple script to display others sellers the same product on product page.

<span><?= /* @escapeNotVerified */ __('Total other sellers:') ?>    
<a class="others-sellers"
                                   href="<?= /* @escapeNotVerified */ $this->getUrl('catalogsearch/result/?q=') ?>"
                                   title="<?= /* @escapeNotVerified */ $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>">
                                    <?= /* @escapeNotVerified */ __('17') ?>
                                </a>
</span>

Issue is related to code:

<a class="others-sellers"
                                       href="<?= /* @escapeNotVerified */ $this->getUrl('catalogsearch/result/?q=') ?>"

This PHP code generate for me link:

https://mywebsite.pl/catalogsearch/result/?q=/

To end URL I need also get attribute EAN and add to URL.
https://mywebsite.pl/catalogsearch/result/?q=83748273423333/

Here I have code how to get EAN. But can anyone help how can i implement this into the code?

<?php $_productNameStripped = $block->stripTags($_product->getEan(), null, true); ?>
            <?php /* @escapeNotVerified */  echo $_helper->productAttribute($_product, $_product->getEan(), 'ean'); ?>

database – Magento 2.4.1 EE | Customer custom attribute created from admin but not saving value in DB

I am facing an issue with Magento2 EE website (Magento ver. 2.4.1) for customer custom attribute.

Found similar question here as well but not with any solutions.

When I create a new customer attribute in admin, attribute created and visible it in admin area but value is not saving. I noticed that the attribute data is not getting saved in the eav_entity_attribute table.

How can I fix it, please suggest.

php – Get attribute label on cart page Woocommerce

Issue/Desired Result

I want to get the attribute_label on the cart page of my Woocommerce store, for example, ‘Size’. My current code is giving me the slug, for example, ‘Attribute_size’.

How can I update my code to get the attribute label?

cart.php Code

// Meta data
    if (!empty($cart_item('variation'))) {
        echo '<div class="variation">';
            foreach ($cart_item('variation') as $key => $variation) {
                echo '<div><span>' . ucwords(str_replace(array('pa_', '-2'), '', $key)) . ':</span>
        <p>' . $variation . '</p></div>';
                                    }
                                echo '</div>';
                            }

csv – how to update a custom attribute in Active Directory?

Hi guys my name is Bastian and I’m a student.
I’m here to ask for help on a script to update users in active directory with CSV file.
I created the columns in the active directory schema, they all appear in the user’s profile when I search for them, but when I perform the update the message says that the parameter does not exist.
The updates through PowerShell directly works and is reflected, but through the CSV file does not find the columns, I need your help to correct my mistake, I would appreciate your guidance.

Import-Module ActiveDirectory (String)$Ruta = Read-Host “Ingrese la ruta donde está el archivo csv (Por Ejemplo C:archivocsv.csv)” $ou=”OU=DominioExtendido” + “,” + (Get-ADDomain).DistinguishedName If(-Not(Get-ADOrganizationalUnit -Filter {Name -eq “DominioExtendido”})){New-ADOrganizationalUnit “DominioExtendido” -Path (Get-ADDomain).DistinguishedName} $dominio=(Get-ADDomain).DNSRoot Import-Csv -Path $Ruta | foreach-object { $UPN = $.Cuenta + “@” + “$dominio” New-ADUser -SamAccountName $.Cuenta -UserPrincipalName $UPN -Name $.Nombre -DisplayName $.Nombre -SurName $.Apellidos -GivenName $.Nombres -Description $.Descripcion -Office $.Oficina -OfficePhone $.Telefono -EmailAddress $.Email -Title $.Titulo -Department $.Departamento -Company $.Compania -City $.Ciudad -State $.Region -AccountPassword (ConvertTo-SecureString $.Clave -AsPlainText -force) -Path $ou -Enabled $true -ChangePasswordAtLogon $true -Verbose -companyCode $_.CodigoEmpresa -companyID $._RutEmpresa -socialReason $._razonSocial -acronymCountryCode $._CodigoPais -contractType $._TipoContrato -businessUnity $._BU -officeLicence $._Licencia365} “”

introducir la descripción de la imagen aquí

database design – Can the derived attribute (eg, age ) be present in the same table with the attribute it is derived from ( DOB)? If no then where should it be present?

I would say this is slightly situational based on the context of the database system / application, and there’s probably merit for storing it either way (in the same table as the field it’s derived from or a separate table), but in general there’s nothing wrong with storing it in the same table. In most cases you’ll find it makes sense and is just generally easier for maintainability.

With best practices for databases, you should avoid storing derived fields in general, when they’re easily derivable, for example an age field in this case, as that’s simply just the current date – the D.O.B. field. The reasoning is because it can lead to data redundancy or be error prone depending on the mechanism used to derive the field. Please note you should also avoid using special characters in field names as another best practice, but that’s outside the scope of this question.

But sometimes it makes sense to store derived fields in the database (usually achievable with calculated / generated fields in most database management systems) when the logic / expression to derive them is complicated and / or performance is a concern. A data warehouse is an example database architecture where storing multiple derived fields to improve querying performance is traded at the cost of data redundancy and additional storage usage.