Exemplo n.º 1
0
 /**
  * Returns a snippet model instance
  *
  * @param   string $namespace
  * @return  Enlight_Components_Snippet_Namespace
  */
 public function getNamespace($namespace = null)
 {
     $key = $namespace === null ? '__ignore' : (string)$namespace;
     if (!isset($this->namespaces[$key])) {
         if (isset($this->fileAdapter) && strpos($namespace, 'backend/') === 0) {
             if (isset($this->locale) && $this->locale->toString() == 'de_DE') {
                 $section = array('de_DE', 'default');
             } else {
                 $section = array('default');
             }
             $this->namespaces[$key] = new $this->defaultNamespaceClass(array(
                 'adapter' => $this->fileAdapter,
                 'name' => $namespace,
                 'section' => $section
             ));
         } elseif ($this->shop !== null) {
             $this->namespaces[$key] = new $this->defaultNamespaceClass(array(
                 'adapter' => $this->adapter,
                 'name' => $namespace,
                 'section' => array(
                     $this->shop->getId(),
                     $this->locale->getId()
                 ),
                 'extends' => $this->extends,
             ));
         } else {
             $this->namespaces[$key] = new $this->defaultNamespaceClass(array(
                 'adapter' => $this->adapter,
                 'name' => $namespace,
                 'section' => $this->defaultSection
             ));
         }
     }
     return $this->namespaces[$key];
 }
Exemplo n.º 2
0
    /**
     * Read data with translations from database
     *
     * @return array
     */
    protected function readData()
    {
        $sql = "
            SELECT
              LOWER(REPLACE(e.name, '_', '')) as name,
              IFNULL(IFNULL(v2.value, v1.value), e.value) as value
            FROM s_core_config_elements e
            LEFT JOIN s_core_config_values v1
            ON v1.element_id = e.id
            AND v1.shop_id = ?
            LEFT JOIN s_core_config_values v2
            ON v2.element_id = e.id
            AND v2.shop_id = ?
        ";
        $data = $this->_db->fetchPairs($sql, array(
            1, //Shop parent id
            isset($this->_shop) ? $this->_shop->getId() : null
        ));

        $result = array();
        foreach ($data as $key => $value) {
            $result[$key] = unserialize($value);
        }

        $result['version'] = Shopware::VERSION;
        $result['revision'] = Shopware::REVISION;
        $result['versiontext'] = Shopware::VERSION_TEXT;

        return $result;
    }
Exemplo n.º 3
0
 /**
  * Read data with translations from database
  *
  * @return array
  */
 protected function readData()
 {
     $sql = "\n            SELECT\n              LOWER(REPLACE(e.name, '_', '')) as name,\n              IFNULL(IFNULL(v2.value, v1.value), e.value) as value,\n              LOWER(REPLACE(forms.name, '_', '')) as form\n            FROM s_core_config_elements e\n            LEFT JOIN s_core_config_values v1\n            ON v1.element_id = e.id\n            AND v1.shop_id = ?\n            LEFT JOIN s_core_config_values v2\n            ON v2.element_id = e.id\n            AND v2.shop_id = ?\n            LEFT JOIN s_core_config_forms forms\n            ON forms.id = e.form_id\n        ";
     $data = $this->_db->fetchAll($sql, array(1, isset($this->_shop) ? $this->_shop->getId() : null));
     $result = array();
     foreach ($data as $row) {
         $result[$row['name']] = unserialize($row['value']);
         // Take namespaces (form names) into account
         $result[$row['form'] . '::' . $row['name']] = unserialize($row['value']);
     }
     $result['version'] = Shopware::VERSION;
     $result['revision'] = Shopware::REVISION;
     $result['versiontext'] = Shopware::VERSION_TEXT;
     return $result;
 }
Exemplo n.º 4
0
 /**
  * Read data with translations from database
  *
  * @return array
  */
 protected function readData()
 {
     $sql = "\n            SELECT\n              LOWER(REPLACE(e.name, '_', '')) as name,\n              COALESCE(currentShop.value, parentShop.value, fallbackShop.value, e.value) as value,\n              LOWER(REPLACE(forms.name, '_', '')) as form,\n              currentShop.value as currentShopval,\n              parentShop.value as parentShopval,\n              fallbackShop.value as fallbackShopval\n\n            FROM s_core_config_elements e\n\n            LEFT JOIN s_core_config_values currentShop\n              ON currentShop.element_id = e.id\n              AND currentShop.shop_id = :currentShopId\n\n            LEFT JOIN s_core_config_values parentShop\n              ON parentShop.element_id = e.id\n              AND parentShop.shop_id = :parentShopId\n\n            LEFT JOIN s_core_config_values fallbackShop\n              ON fallbackShop.element_id = e.id\n              AND fallbackShop.shop_id = :fallbackShopId\n\n            LEFT JOIN s_core_config_forms forms\n              ON forms.id = e.form_id\n        ";
     $data = $this->_db->fetchAll($sql, array('fallbackShopId' => 1, 'parentShopId' => isset($this->_shop) && $this->_shop->getMain() !== null ? $this->_shop->getMain()->getId() : 1, 'currentShopId' => isset($this->_shop) ? $this->_shop->getId() : null));
     $result = array();
     foreach ($data as $row) {
         $value = !empty($row['value']) ? @unserialize($row['value']) : null;
         $result[$row['name']] = $value;
         // Take namespaces (form names) into account
         $result[$row['form'] . '::' . $row['name']] = $value;
     }
     $result['version'] = Shopware::VERSION;
     $result['revision'] = Shopware::REVISION;
     $result['versiontext'] = Shopware::VERSION_TEXT;
     return $result;
 }
Exemplo n.º 5
0
 /**
  * Returns a snippet model instance
  *
  * @param   string $namespace
  * @return  Enlight_Components_Snippet_Namespace
  */
 public function getNamespace($namespace = null)
 {
     $key = $namespace === null ? '__ignore' : (string) $namespace;
     if (!isset($this->namespaces[$key])) {
         if ($this->snippetConfig['readFromDb']) {
             $this->namespaces[$key] = new $this->defaultNamespaceClass(array('adapter' => $this->adapter, 'name' => $namespace, 'section' => array($this->shop ? $this->shop->getId() : 1, $this->locale ? $this->locale->getId() : $this->getDefaultLocale()->getId()), 'extends' => $this->extends));
         }
         if ($this->snippetConfig['readFromIni'] && (!isset($this->namespaces[$key]) || count($this->namespaces[$key]) == 0) && isset($this->fileAdapter)) {
             $fullNamespace = new $this->defaultNamespaceClass(array('adapter' => $this->fileAdapter, 'name' => $namespace, 'section' => null));
             $locale = $this->locale ? $this->locale->getLocale() : $this->getDefaultLocale()->getLocale();
             if (!array_key_exists($locale, $fullNamespace->toArray()) && in_array($locale, array('en_GB', 'default')) && count(array_keys($fullNamespace->toArray()))) {
                 $locale = array_shift(array_diff(array('en_GB', 'default'), array($locale)));
             }
             $fullNamespace->setSection($locale);
             $fullNamespace->setData($fullNamespace->get($locale));
             $this->namespaces[$key] = $fullNamespace;
         }
     }
     if (!isset($this->namespaces[$key])) {
         $this->namespaces[$key] = new $this->defaultNamespaceClass(array('name' => $namespace));
     }
     return $this->namespaces[$key];
 }
    /**
     * 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
                }
            }
        }
    }
Exemplo n.º 7
0
 /**
  * @param array $params
  * @return \Shopware\Models\Shop\Shop
  * @throws \Shopware\Components\Api\Exception\ValidationException
  * @throws \Exception
  */
 public function create(array $params)
 {
     $this->checkPrivilege('create');
     $params = $this->prepareShopData($params);
     $shop = new \Shopware\Models\Shop\Shop();
     $shop->fromArray($params);
     $violations = $this->getManager()->validate($shop);
     if ($violations->count() > 0) {
         throw new ApiException\ValidationException($violations);
     }
     $this->getManager()->persist($shop);
     $this->flush();
     return $shop;
 }