source/Application/Model/Attribute.php
public function assignVarToAttribute($aMDVariants, $aSelTitle)
    {
        $myLang = \OxidEsales\Eshop\Core\Registry::getLang();
        $aConfLanguages = $myLang->getLanguageIds();
        $sAttrId = $this->_getAttrId($aSelTitle[0]);
        if (!$sAttrId) {
            $sAttrId = $this->_createAttribute($aSelTitle);
        }
        foreach ($aMDVariants as $sVarId => $oValue) {
            if (strpos($sVarId, "mdvar_") === 0) {
                foreach ($oValue as $sId) {
                    $sVarId = substr($sVarId, 6);
                    $oNewAssign = oxNew(\OxidEsales\Eshop\Core\Model\BaseModel::class);
                    $oNewAssign->init("oxobject2attribute");
                    $sNewId = \OxidEsales\Eshop\Core\Registry::getUtilsObject()->generateUID();
                    if ($oNewAssign->load($sId)) {
                        $oNewAssign->oxobject2attribute__oxobjectid = new \OxidEsales\Eshop\Core\Field($sVarId);
                        $oNewAssign->setId($sNewId);
                        $oNewAssign->save();
                    }
                }
            } else {
                $oNewAssign = oxNew(\OxidEsales\Eshop\Core\Model\MultiLanguageModel::class);
                $oNewAssign->setEnableMultilang(false);
                $oNewAssign->init("oxobject2attribute");
                $oNewAssign->oxobject2attribute__oxobjectid = new \OxidEsales\Eshop\Core\Field($sVarId);
                $oNewAssign->oxobject2attribute__oxattrid = new \OxidEsales\Eshop\Core\Field($sAttrId);
                foreach ($aConfLanguages as $sKey => $sLang) {
                    $sPrefix = $myLang->getLanguageTag($sKey);
                    $oNewAssign->{'oxobject2attribute__oxvalue' . $sPrefix} = new \OxidEsales\Eshop\Core\Field($oValue[$sKey]->name);
                }
                $oNewAssign->save();
            }
        }
    }
public function assignVarToAttribute($aMDVariants, $aSelTitle)
    {
        $myLang = \OxidEsales\Eshop\Core\Registry::getLang();
        $aConfLanguages = $myLang->getLanguageIds();
        $sAttrId = $this->_getAttrId($aSelTitle[0]);
        if (!$sAttrId) {
            $sAttrId = $this->_createAttribute($aSelTitle);
        }
        foreach ($aMDVariants as $sVarId => $oValue) {
            if (strpos($sVarId, "mdvar_") === 0) {
                foreach ($oValue as $sId) {
                    $sVarId = substr($sVarId, 6);
                    $oNewAssign = oxNew(\OxidEsales\Eshop\Core\Model\BaseModel::class);
                    $oNewAssign->init("oxobject2attribute");
                    $sNewId = \OxidEsales\Eshop\Core\Registry::getUtilsObject()->generateUID();
                    if ($oNewAssign->load($sId)) {
                        $oNewAssign->oxobject2attribute__oxobjectid = new \OxidEsales\Eshop\Core\Field($sVarId);
                        $oNewAssign->setId($sNewId);
                        $oNewAssign->save();
                    }
                }
            } else {
                $oNewAssign = oxNew(\OxidEsales\Eshop\Core\Model\MultiLanguageModel::class);
                $oNewAssign->setEnableMultilang(false);
                $oNewAssign->init("oxobject2attribute");
                $oNewAssign->oxobject2attribute__oxobjectid = new \OxidEsales\Eshop\Core\Field($sVarId);
                $oNewAssign->oxobject2attribute__oxattrid = new \OxidEsales\Eshop\Core\Field($sAttrId);
                foreach ($aConfLanguages as $sKey => $sLang) {
                    $sPrefix = $myLang->getLanguageTag($sKey);
                    $oNewAssign->{'oxobject2attribute__oxvalue' . $sPrefix} = new \OxidEsales\Eshop\Core\Field($oValue[$sKey]->name);
                }
                $oNewAssign->save();
            }
        }
    }
public function assignVarToAttribute ( $ aMDVariants , $ aSelTitle ) { $ myLang = \ OxidEsales \ Eshop \ Core \ Registry :: getLang ( ) ; $ aConfLanguages = $ myLang -> getLanguageIds ( ) ; $ sAttrId = $ this -> _getAttrId ( $ aSelTitle [ 0 ] ) ; if ( ! $ sAttrId ) { $ sAttrId = $ this -> _createAttribute ( $ aSelTitle ) ; } foreach ( $ aMDVariants as $ sVarId => $ oValue ) { if ( strpos ( $ sVarId , "mdvar_" ) === 0 ) { foreach ( $ oValue as $ sId ) { $ sVarId = substr ( $ sVarId , 6 ) ; $ oNewAssign = oxNew ( \ OxidEsales \ Eshop \ Core \ Model \ BaseModel :: class ) ; $ oNewAssign -> init ( "oxobject2attribute" ) ; $ sNewId = \ OxidEsales \ Eshop \ Core \ Registry :: getUtilsObject ( ) -> generateUID ( ) ; if ( $ oNewAssign -> load ( $ sId ) ) { $ oNewAssign -> oxobject2attribute__oxobjectid = new \ OxidEsales \ Eshop \ Core \ Field ( $ sVarId ) ; $ oNewAssign -> setId ( $ sNewId ) ; $ oNewAssign -> save ( ) ; } } } else { $ oNewAssign = oxNew ( \ OxidEsales \ Eshop \ Core \ Model \ MultiLanguageModel :: class ) ; $ oNewAssign -> setEnableMultilang ( false ) ; $ oNewAssign -> init ( "oxobject2attribute" ) ; $ oNewAssign -> oxobject2attribute__oxobjectid = new \ OxidEsales \ Eshop \ Core \ Field ( $ sVarId ) ; $ oNewAssign -> oxobject2attribute__oxattrid = new \ OxidEsales \ Eshop \ Core \ Field ( $ sAttrId ) ; foreach ( $ aConfLanguages as $ sKey => $ sLang ) { $ sPrefix = $ myLang -> getLanguageTag ( $ sKey ) ; $ oNewAssign -> { 'oxobject2attribute__oxvalue' . $ sPrefix } = new \ OxidEsales \ Eshop \ Core \ Field ( $ oValue [ $ sKey ] -> name ) ; } $ oNewAssign -> save ( ) ; } } }
Assigns attribute to variant

@param array $aMDVariants article ids with selectionlist values
@param array $aSelTitle   selection list titles
Assigns attribute to variant