/**
  * @param int $shopId
  */
 public function importPropertyGroupTranslation($shopId)
 {
     try {
         $SHOPWARE_id = PlentymarketsMappingController::getPropertyGroupByPlentyID($this->Group->PropertyGroupID);
         PyLog()->message('Sync:Item:Property Group', 'Updating the property group translation »' . $this->Group->FrontendName . '«');
     } catch (PlentymarketsMappingExceptionNotExistant $E) {
         PyLog()->message('Sync:Item:Property Group', 'Skipping the property group translation »' . $this->Group->FrontendName . '«');
         return;
     }
     if (!is_null($this->Group->FrontendName)) {
         // save the translation of the property group
         $properteryGroup_TranslationData = array('groupName' => $this->Group->FrontendName);
         $propertyParts = explode(';', $SHOPWARE_id);
         $groupId = $propertyParts[0];
         PlentymarketsTranslation::setShopwareTranslation('propertygroup', $groupId, $shopId, $properteryGroup_TranslationData);
     }
 }
    /**
     * Import all translation of the PropertyValue
     */
    public function importItemPropertyValueTranslations()
    {
        // array with item properties only in German
        $german_itemProperties = array_filter($this->ItemBase->ItemProperties->item, function ($property) {
            return $property->PropertyValueLang == 'de';
        });
        // array with item properties only in german
        $otherLang_itemProperties = array_filter($this->ItemBase->ItemProperties->item, function ($property) {
            return !($property->PropertyValueLang == 'de');
        });
        // Properties in other languages as German
        /** @var PlentySoapObject_ItemProperty $ItemProperty */
        foreach ($otherLang_itemProperties as $ItemProperty) {
            // search for the german property value to get afterwards the shopware property value id from tb: s_filter_values
            /** @var PlentySoapObject_ItemProperty $germanProperty */
            foreach ($german_itemProperties as $germanProperty) {
                if ($germanProperty->PropertyID == $ItemProperty->PropertyID) {
                    // the german Property is found
                    break;
                }
            }
            // search for the shopware language shop
            $shopId = null;
            // get all active languages of the main shop
            $activeLanguages = PlentymarketsTranslation::getShopActiveLanguages($this->Shop->getId());
            // search the language shop with the language equal with the property language
            foreach ($activeLanguages as $localeId => $language) {
                if (PlentymarketsTranslation::getPlentyLocaleFormat($language['locale']) == $ItemProperty->PropertyValueLang) {
                    // if the founded shop is a language shop
                    if (!is_null($language['mainShopId'])) {
                        $shopId = PlentymarketsTranslation::getLanguageShopID($localeId, $language['mainShopId']);
                    } else {
                        // the main shop has the same language as the property
                        $shopId = $this->Shop->getId();
                    }
                }
            }
            // if the language shop was found, save the property value for this language shop
            if (!is_null($shopId)) {
                // try to get the property value Id from TB : s_filter_values
                // !! in TB: s_filter_values the values are saved in the German language = $germanProperty->PropertyValue
                try {
                    $shopware_property = PlentymarketsMappingController::getPropertyByPlentyID($ItemProperty->PropertyID);
                    $parts = explode(';', $shopware_property);
                    $shopware_propertyID = $parts[1];
                    $sql = 'SELECT id
						FROM s_filter_values
						WHERE optionID =' . $shopware_propertyID . ' AND value LIKE "%' . $germanProperty->PropertyValue . '%"';
                    $response = Shopware()->Db()->query($sql)->fetchAll();
                    $shopware_propertyValueID = $response[0]['id'];
                    if (!is_null($shopware_propertyValueID)) {
                        // save the translation of the property
                        $property_data = array('optionValue' => $ItemProperty->PropertyValue);
                        PlentymarketsTranslation::setShopwareTranslation('propertyvalue', $shopware_propertyValueID, $shopId, $property_data);
                    }
                } catch (Exception $e) {
                    // throw exception
                }
            }
        }
    }
 /**
  * @param $shopware_ImageID int
  * @param $plenty_ImageNames PlentySoapResponse_ObjectGetItemImageName[]
  * @param $shopware_storeID int
  */
 private function importImageTitleTranslation($shopware_ImageID, $plenty_ImageNames, $shopware_storeID)
 {
     // get all active languages of the main shop
     $activeLanguages = PlentymarketsTranslation::getShopActiveLanguages($shopware_storeID);
     foreach ($activeLanguages as $localeId => $language) {
         /**
          * @var $plentyImageName  PlentySoapResponse_ObjectGetItemImageName
          */
         foreach ($plenty_ImageNames as $plentyImageName) {
             if (!is_null($plentyImageName->Name) && strlen($plentyImageName->Name) > 0) {
                 // search the language shop with the language equal as the image name language
                 if (PlentymarketsTranslation::getPlentyLocaleFormat($language['locale']) == $plentyImageName->Lang) {
                     $shopId = null;
                     // if the founded shop is a language shop
                     if (!is_null($language['mainShopId'])) {
                         $shopId = PlentymarketsTranslation::getLanguageShopID($localeId, $language['mainShopId']);
                     } elseif (PlentymarketsTranslation::getPlentyLocaleFormat($language['locale']) != 'de') {
                         // set the imagae title translation for the main shop that has the main language other as German
                         $shopId = $shopware_storeID;
                     }
                     // if the language shop was found / set , save the image title translation for this language shop
                     if (!is_null($shopId)) {
                         // save the translation of the plenty image title
                         $image_data = array('description' => $plentyImageName->Name);
                         PlentymarketsTranslation::setShopwareTranslation('articleimage', $shopware_ImageID, $shopId, $image_data);
                     }
                 }
             }
         }
     }
 }
 /**
  * Imports the attribute and the values translations for the language shops
  * @param $languageShopId int
  */
 public function importTranslation($languageShopId)
 {
     if (is_null($this->Attribute->FrontendName)) {
         return;
     }
     try {
         $SHOPWARE_attributeId = PlentymarketsMappingController::getAttributeGroupByPlentyID($this->Attribute->Id);
         PyLog()->message('Sync:Item:Attribute', 'Updating the attribute translation »' . $this->Attribute->FrontendName . '«');
     } catch (PlentymarketsMappingExceptionNotExistant $E) {
         PyLog()->message('Sync:Item:Attribute', 'Skipping the attribute translation »' . $this->Attribute->FrontendName . '«');
         return;
     }
     // save the translation of the attribute
     $attr_translationData = array('name' => $this->Attribute->FrontendName);
     PlentymarketsTranslation::setShopwareTranslation('configuratorgroup', $SHOPWARE_attributeId, $languageShopId, $attr_translationData);
     /**
      * @var PlentySoapObject_GetItemAttributesAttributeValue $plentyAttributeValue
      */
     foreach ($this->Attribute->Values->item as $plentyAttributeValue) {
         try {
             $SHOPWARE_optionId = PlentymarketsMappingController::getAttributeOptionByPlentyID($plentyAttributeValue->ValueId);
         } catch (PlentymarketsMappingExceptionNotExistant $E) {
             continue;
         }
         if (!is_null($plentyAttributeValue->FrontendName)) {
             $attrValue_translationData = array('name' => $plentyAttributeValue->FrontendName);
             PlentymarketsTranslation::setShopwareTranslation('configuratoroption', $SHOPWARE_optionId, $languageShopId, $attrValue_translationData);
         }
     }
 }