/**
  * Does the actual import
  */
 public function import()
 {
     try {
         $SHOPWARE_id = PlentymarketsMappingController::getPropertyByPlentyID($this->Option->PropertyID);
         PyLog()->message('Sync:Item:Property:Option', 'Updating the property option »' . $this->Option->PropertyFrontendName . '«');
     } catch (PlentymarketsMappingExceptionNotExistant $E) {
         PyLog()->message('Sync:Item:Property:Option', 'Skipping the property option »' . $this->Option->PropertyFrontendName . '«');
         return;
     }
     $propertyParts = explode(';', $SHOPWARE_id);
     $optionId = $propertyParts[1];
     /** @var Shopware\Models\Property\Option $Option */
     $Option = Shopware()->Models()->find('Shopware\\Models\\Property\\Option', $optionId);
     // Set the new data
     $Option->setName($this->Option->PropertyFrontendName);
     Shopware()->Models()->persist($Option);
     Shopware()->Models()->flush();
 }
    /**
     * 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
                }
            }
        }
    }