コード例 #1
0
ファイル: EbayCategorySpecific.php プロジェクト: poonc/ebay
    /**
     * Parse the data returned by the API and enter them in the table
     *
     **/
    public static function loadCategorySpecifics($id_ebay_profile)
    {
        $request = new EbayRequest($id_ebay_profile);
        $ebay_category_ids = EbayCategoryConfiguration::getEbayCategoryIds($id_ebay_profile);
        $ebay_profile = new EbayProfile($id_ebay_profile);
        foreach ($ebay_category_ids as $ebay_category_id) {
            $xml_data = $request->GetCategorySpecifics($ebay_category_id);
            if ($xml_data->Recommendations->NameRecommendation) {
                foreach ($xml_data->Recommendations->NameRecommendation as $recommendation) {
                    $required = isset($recommendation->ValidationRules->MinValues) && (int) $recommendation->ValidationRules->MinValues >= 1;
                    // if true can be used either in Item Specifics or VariationSpecifics
                    $can_variation = !(isset($recommendation->ValidationRules->VariationSpecifics) && (string) $recommendation->ValidationRules->VariationSpecifics == 'Disabled');
                    if (isset($recommendation->ValidationRules->SelectionMode)) {
                        if ((string) $recommendation->ValidationRules->SelectionMode == 'Prefilled') {
                            continue;
                        } elseif ((string) $recommendation->ValidationRules->SelectionMode == 'SelectionOnly') {
                            $selection_mode = EbayCategorySpecific::SELECTION_MODE_SELECTION_ONLY;
                        } else {
                            $selection_mode = EbayCategorySpecific::SELECTION_MODE_FREE_TEXT;
                        }
                    } else {
                        $selection_mode = EbayCategorySpecific::SELECTION_MODE_FREE_TEXT;
                    }
                    $values = array();
                    if (isset($recommendation->ValueRecommendation->Value)) {
                        foreach ($recommendation->ValueRecommendation as $value_recommendation) {
                            $values[] = (string) $value_recommendation->Value;
                        }
                    }
                    $db = Db::getInstance();
                    $db->execute('INSERT INTO `' . _DB_PREFIX_ . 'ebay_category_specific` (`id_category_ref`, `name`, `required`, `can_variation`, `selection_mode`, `ebay_site_id`)
						VALUES (' . (int) $ebay_category_id . ', \'' . pSQL((string) $recommendation->Name) . '\', ' . ($required ? 1 : 0) . ', ' . ($can_variation ? 1 : 0) . ', ' . ($selection_mode ? 1 : 0) . ', ' . (int) $ebay_profile->ebay_site_id . ')
						ON DUPLICATE KEY UPDATE `required` = ' . ($required ? 1 : 0) . ', `can_variation` = ' . ($can_variation ? 1 : 0) . ', `selection_mode` = ' . ($selection_mode ? 1 : 0));
                    $ebay_category_specific_id = $db->Insert_ID();
                    if (!$ebay_category_specific_id) {
                        $ebay_category_specific_id = $db->getValue('SELECT `id_ebay_category_specific`
							FROM `' . _DB_PREFIX_ . 'ebay_category_specific`
							WHERE `id_category_ref` = ' . (int) $ebay_category_id . '
							AND `ebay_site_id` = ' . (int) $ebay_profile->ebay_site_id . '
							AND `name` = \'' . pSQL((string) $recommendation->Name) . '\'');
                    }
                    $insert_data = array();
                    foreach ($values as $value) {
                        $insert_data[] = array('id_ebay_category_specific' => (int) $ebay_category_specific_id, 'value' => pSQL($value));
                    }
                    EbayCategorySpecificValue::insertIgnore($insert_data);
                }
            }
        }
        return true;
    }
コード例 #2
0
    /**
     *
     * Parse the data returned by the API for the eBay Category Conditions
     **/
    public static function loadCategoryConditions($id_ebay_profile)
    {
        $request = new EbayRequest($id_ebay_profile);
        $ebay_category_ids = EbayCategoryConfiguration::getEbayCategoryIds((int) $id_ebay_profile);
        $conditions = array();
        foreach ($ebay_category_ids as $category_id) {
            $xml_data = $request->GetCategoryFeatures($category_id);
            if (isset($xml_data->Category->ConditionEnabled)) {
                $condition_enabled = $xml_data->Category->ConditionEnabled;
            } else {
                $condition_enabled = $xml_data->SiteDefaults->ConditionEnabled;
            }
            if (!$condition_enabled) {
                return;
            }
            if (isset($xml_data->Category->ConditionValues->Condition)) {
                $xml_conditions = $xml_data->Category->ConditionValues->Condition;
            } else {
                $xml_conditions = $xml_data->SiteDefaults->ConditionValues->Condition;
            }
            if ($xml_conditions) {
                foreach ($xml_conditions as $xml_condition) {
                    $conditions[] = array('id_ebay_profile' => (int) $id_ebay_profile, 'id_category_ref' => (int) $category_id, 'id_condition_ref' => (int) $xml_condition->ID, 'name' => pSQL((string) $xml_condition->DisplayName));
                }
            }
            //
            Db::getInstance()->ExecuteS("SELECT 1");
        }
        if ($conditions) {
            $db = Db::getInstance();
            $db->Execute('DELETE FROM ' . _DB_PREFIX_ . 'ebay_category_condition 
				WHERE `id_ebay_profile` = ' . (int) $id_ebay_profile);
            if (version_compare(_PS_VERSION_, '1.5', '>')) {
                $db->insert('ebay_category_condition', $conditions);
            } else {
                foreach ($conditions as $condition) {
                    $db->autoExecute(_DB_PREFIX_ . 'ebay_category_condition', $condition, 'INSERT');
                }
            }
            return true;
        }
        return false;
    }