Plugin Directory

Changeset 3484553


Ignore:
Timestamp:
03/17/2026 08:24:51 AM (3 weeks ago)
Author:
avecdo
Message:

Bump version to 1.8.1 and update tested up to version 6.9.4

Location:
avecdo-for-woocommerce/trunk
Files:
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • avecdo-for-woocommerce/trunk/avecdo.php

    r3463216 r3484553  
    44 * Plugin URI: https://avecdo.com/
    55 * Description: avecdo connector plugin for WooCommerce
    6  * Version: 1.8.0
     6 * Version: 1.8.1
    77 * Author: Modified Solutions ApS
    88 * Author URI: https://www.modified.dk/
     
    1010 * Developer URI: https://www.modified.dk/
    1111 * Requires at least: 4.5
    12  * Tested up to: 6.9.1
     12 * Tested up to: 6.9.4
    1313 * WC requires at least: 2.6.0
    14  * WC tested up to: 8.1.1
     14 * WC tested up to: 10.5.1
    1515 *
    1616 * Text Domain: avecdo-for-woocommerce
     
    3434 * @var string Version string
    3535 */
    36 define('AVECDO_WOOCOMMERCE_PLUGIN_VERSION', '1.8.0');
     36define('AVECDO_WOOCOMMERCE_PLUGIN_VERSION', '1.8.1');
    3737
    3838/**
     
    5050$avecdoPlugin->loadTextdomain();
    5151$avecdoPlugin->registerPluginActions();
    52 
    53 add_option('avecdo_version', 1);
    5452
    5553/*
     
    8078    $plugin->render();
    8179}
    82 
    83 
    84 
    8580
    8681if (!function_exists('avecdo_safe_redirect')) {
     
    197192}
    198193
    199 if (!function_exists('avecdoValidateWooCommerceVersion')) {
    200 
    201     /**
    202      * Validate the current WooCommerce version
    203      *
    204      * @staticvar type $wooCommerceVersion
    205      * @staticvar array $cachedVersionCompare
    206      * @param type $version
    207      * @param type $operator
    208      * @return boolean
    209      * @author Christian M. Jensen <christian@modified.dk>
    210      * @since 1.1.2
    211      */
    212     function avecdoValidateWooCommerceVersion($version, $operator = "=")
    213     {
    214         static $wooCommerceVersion   = null;
    215         static $cachedVersionCompare = array();
    216         if (!is_null($wooCommerceVersion)) {
    217             if (!isset($cachedVersionCompare["{$version}_{$operator}"])) {
    218                 $cachedVersionCompare["{$version}_{$operator}"] = version_compare($wooCommerceVersion, $version, $operator);
    219             }
    220             return $cachedVersionCompare["{$version}_{$operator}"];
    221         }
    222         if (!function_exists('get_plugins')) {
    223             require_once( ABSPATH.'wp-admin/includes/plugin.php' );
    224         }
    225         $plugin_folder = get_plugins('/'.'woocommerce');
    226         $plugin_file   = 'woocommerce.php';
    227         if (isset($plugin_folder[$plugin_file]['Version'])) {
    228             $wooCommerceVersion = $plugin_folder[$plugin_file]['Version'];
    229             return version_compare($wooCommerceVersion, $version, $operator);
    230         }
    231         return false;
    232     }
    233 }
    234 if (!function_exists('avecdoGetImageTitleFromMeta')) {
    235 
    236     /**
    237      * Get image title/caption from metadata array.
    238      * @param array $metadata
    239      * @param string $imagealt
    240      * @return string defaults to $imagealt
    241      */
    242     function avecdoGetImageTitleFromMeta($metadata, $imagealt)
    243     {
    244         if (!is_array($metadata)) {
    245             return $imagealt;
    246         }
    247         if (!empty($metadata) && isset($metadata['image_meta'])) {
    248             $metadata = $metadata['image_meta'];
    249         }
    250         $text = "";
    251         if (isset($metadata['caption'])) {
    252             $text = $metadata['caption'];
    253         }
    254         if (empty($text) && isset($metadata['title'])) {
    255             $text = $metadata['title'];
    256         }
    257         if (empty($text)) {
    258             $text = $imagealt;
    259         }
    260         return $text;
    261     }
    262 }
    263 
    264 
    265 if (!function_exists('avecdoGetAttachmentRelativePath')) {
    266 
    267     /**
    268      * Get the relative path to an attachment under the upload folder
    269      * @param file $file
    270      * @return string
    271      * @author Christian M. Jensen <christian@modified.dk>
    272      * @since 1.1.2
    273      */
    274     function avecdoGetAttachmentRelativePath($file)
    275     {
    276         $dirname = dirname($file);
    277         if ('.' === $dirname) {
    278             return '';
    279         }
    280         if (false !== strpos($dirname, 'wp-content/uploads')) {
    281             // Get the directory name relative to the upload directory (back compat for pre-2.7 uploads)
    282             $dirname = substr($dirname, strpos($dirname, 'wp-content/uploads') + 18);
    283             return ltrim($dirname, '/');
    284         }
    285         return $dirname;
    286     }
    287 }
    288 
    289 if (!function_exists('avecdoBuildFullMediaUrl')) {
    290 
    291     /**
    292      * Build and return the full web url to $file
    293      * @param string $file partial path to file.
    294      * @param int $fileId database id of the file
    295      * @return string
    296      * @author Christian M. Jensen <christian@modified.dk>
    297      * @since 1.1.2
    298      */
    299     function avecdoBuildFullMediaUrl($file, $fileId)
    300     {
    301         $url     = '';
    302         // Get upload directory.
    303         if (($uploads = wp_upload_dir(null, false)) && false === $uploads['error']) {
    304             // Check that the upload base exists in the file location.
    305             if (0 === strpos($file, $uploads['basedir'])) {
    306                 // Replace file location with url location.
    307                 $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file);
    308             } elseif (false !== strpos($file, 'wp-content/uploads')) {
    309                 // Get the directory name relative to the basedir (back compat for pre-2.7 uploads)
    310                 $url = trailingslashit($uploads['baseurl'].'/'.avecdoGetAttachmentRelativePath($file)).basename($file);
    311             } else {
    312                 // It's a newly-uploaded file, therefore $file is relative to the basedir.
    313                 $url = $uploads['baseurl']."/$file";
    314             }
    315         }
    316         if (empty($url)) {
    317             $url = avecdoQueryPostGuid($fileId);
    318         }
    319         if (empty($url)) {
    320             return "";
    321         }
    322         return set_url_scheme($url);
    323     }
    324 }
    325 
    326 if (!function_exists('avecdoQueryPostGuid')) {
    327 
    328     /**
    329      * get value of guid from posts table
    330      * @global wpdb $wpdb
    331      * @param int $fileId
    332      * @return string
    333      * @author Christian M. Jensen <christian@modified.dk>
    334      * @since 1.1.2
    335      */
    336     function avecdoQueryPostGuid($fileId)
    337     {
    338         if (((int) $fileId > 0)) {
    339             global $wpdb;
    340             $query_result = $wpdb->get_results("SELECT guid FROM ".$wpdb->prefix."posts WHERE ID=".intval($fileId), OBJECT);
    341             return !empty($query_result) ? (is_array($query_result) ? $query_result[0]->guid : "") : "";
    342         }
    343         return "";
    344     }
    345 }
    346 
    347194// Set WooCommerce HPOS compatibility
    348195add_action( 'before_woocommerce_init', function() {
  • avecdo-for-woocommerce/trunk/readme.txt

    r3463216 r3484553  
    33Tags: feed, service, avecdo, Facebook, Google Shopping, shopping, woocommerce, kelkoo, miinto, Pricerunner, Partner-ads, ecommerce, e-commerce
    44Requires at least: 4.5
    5 Tested up to: 6.9.1
    6 Stable tag: 1.8.0
     5Tested up to: 6.9.4
     6Stable tag: 1.8.1
    77License: Mozilla Public License Version 2.0
    88License URI: https://www.mozilla.org/en-US/MPL/2.0/
     
    4545
    4646== Changelog ==
     47
     48= 1.8.1 =
     49* Remove unused code and files
     50* Updated tested up to version 6.9.4
    4751
    4852= 1.8.0 =
  • avecdo-for-woocommerce/trunk/src/Classes/Option.php

    r3463216 r3484553  
    9898    private static function getFullName($name)
    9999    {
    100         switch (self::getVersion()) {
    101             case 1:
    102                 return 'avecdo_' . $name;
    103             case 2:
    104                 return 'avecdo_v2_' . $name;
    105         }
    106         return null;
    107     }
    108 
    109     public static function getVersion()
    110     {
    111         $headers = Helpers::getAllHeaders();
    112         if (key_exists('user-agent', $headers)) {
    113             switch ($headers['user-agent']) {
    114                 case 'avecdo (+https://avecdo.com)':
    115                 case 'avecdo/1.0 (+https://avecdo.com)':
    116                     return 1;
    117                 case 'avecdo/2.0 (+https://avecdo.com)':
    118                     return 2;
    119             }
    120         }
    121 
    122         return get_option('avecdo_version');
     100        return 'avecdo_v2_' . $name;
    123101    }
    124102}
  • avecdo-for-woocommerce/trunk/src/Classes/Plugin.php

    r3463216 r3484553  
    2424    const WOOCOMMERCE_NOT_ACTIVE     = 'WooCommerce is not activated.';
    2525    const NOT_SUFFICIENT_PERMISSIONS = 'You do not have sufficient permissions to access this page.';
    26     const ERROR_CODE_INTERFACE       = 6872;
    2726    const WPML_ACTIVE_BUT_NOT_WCML   = 'Please install "WooCommerce Multilingual" and go to WooCommerce->WooCommerce Multilingual->Multi-currency and "enable multi currency mode" for multi language/multi currency support.';
    2827
     
    153152    }
    154153
    155     public function prepareMultiCurrency($multiCurrencyEnabled, &$languages, &$currencies)
     154    public function prepareMultiCurrency(&$languages, &$currencies)
    156155    {
    157156        // WooCommerce Multilingual with Multi-currency.
    158         if ($multiCurrencyEnabled) {
    159             global $woocommerce_wpml;
    160             $languages = apply_filters( 'wpml_active_languages', array(), array( 'skip_missing' => 0));
    161 
    162             // Sort languages by code.
    163             if ( ! empty( $languages ) ) {
    164                 uasort( $languages, function ( $a, $b ) {
    165                     return strcmp( $a['code'], $b['code'] );
    166                 });
    167             }
    168 
    169             // Invert the currency list, so that we go from language to available currencies,
    170             // instead of available currencies to language.
    171             foreach ($woocommerce_wpml->multi_currency->currencies as $currency_id => $currency_langs) {
    172                 foreach ($currency_langs['languages'] as $lang_code => $lang_enabled) {
    173                     if ($lang_enabled) {
    174                         $currencies[$lang_code][] = $currency_id;
    175                     }
     157        global $woocommerce_wpml;
     158        $languages = apply_filters( 'wpml_active_languages', array(), array( 'skip_missing' => 0));
     159
     160        // Sort languages by code.
     161        if ( ! empty( $languages ) ) {
     162            uasort( $languages, function ( $a, $b ) {
     163                return strcmp( $a['code'], $b['code'] );
     164            });
     165        }
     166
     167        // Invert the currency list, so that we go from language to available currencies,
     168        // instead of available currencies to language.
     169        foreach ($woocommerce_wpml->multi_currency->currencies as $currency_id => $currency_langs) {
     170            foreach ($currency_langs['languages'] as $lang_code => $lang_enabled) {
     171                if ($lang_enabled) {
     172                    $currencies[$lang_code][] = $currency_id;
    176173                }
    177174            }
     
    205202                }
    206203
    207                 $this->prepareMultiCurrency($multiCurrencyEnabled, $languages, $currencies);
     204                $this->prepareMultiCurrency( $languages, $currencies);
    208205
    209206                if (empty($languages)) {
     
    216213
    217214        $activationKey = $this->keySet->asString();
    218         $mesages       = $this->messages;
     215        $messages       = $this->messages;
    219216        $activation    = false;
    220         $versionSelected = $_POST['version'] ?? get_option('avecdo_version');
    221 
    222         if ((isset($_GET['activation']) && !isset($_POST['avecdo_submit_reset'])) || isset($_POST['version'])) {
     217
     218        if (isset($_GET['activation']) && !isset($_POST['avecdo_submit_reset'])) {
    223219            $activation = true;
    224220        }
     
    232228        $content = ob_get_clean();
    233229        echo $content;
    234     }
    235 
    236     public function getWPMLShopOptions() {
    237         if(Option::get('multi_lang_props')){
    238             return json_decode(Option::get('multi_lang_props'), true);
    239         }
    240 
    241         return null;
    242     }
    243 
    244     public function setWPMLShopOptions($options) {
    245         Option::update('multi_lang_props', json_encode($options));
    246230    }
    247231
     
    298282    {
    299283        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    300 
    301284            if (isset($_POST['avecdo_lang_settings'])) {
    302285                $this->handleWPMLSettings();
     
    304287            }
    305288
    306             $isMultiLang = false;
    307             if (isset($_POST['avecdo_multi_lang']) && $_POST['avecdo_multi_lang'] === '1') {
    308                 $isMultiLang = true;
    309             }
    310 
    311289            if (isset($_POST['avecdo_submit_activation'])) {
    312                 $activated = $this->activationSubmitted($isMultiLang, $_POST);
     290                $activated = $this->activationSubmitted();
    313291                if (!$activated) {
    314292                    return;
     
    316294
    317295            } else if (isset($_POST['avecdo_submit_reset']) && $_POST['avecdo_submit_reset'] == '1') {
    318                 $this->resetSubmitted($isMultiLang, $_POST);
    319             } else if (isset($_POST['version']) && in_array($_POST['version'], ['1', '2'])) {
    320                 update_option('avecdo_version', intval($_POST['version']));
     296                $this->resetSubmitted();
     297            } else {
    321298                $this->updateKeySet();
    322299            }
     
    329306            Option::update('use_description', $_POST['use_description']);
    330307
    331             if (!$isMultiLang) {
    332                 if (isset($_POST['AVECDO_CURRENCY_ID'])) {
    333                     // If the shop has multi-currency plugin installed:
    334                     Option::update('currency', $_POST['AVECDO_CURRENCY_ID']);
    335                     Option::update('language', $_POST['AVECDO_LANGUAGE_ID']);
    336                 } else {
    337                     // If there is no multi-currency enabled (or it has been disabled),
    338                     // use the default woocommerce currency.
    339                     Option::update('currency', get_woocommerce_currency());
    340                 }
    341             } else {
    342 
    343                 $multiLangShopData = $this->getWPMLShopOptions();
    344                 $langCode = isset($_POST['AVECDO_PREVIOUS_LANG_ID']) ? $_POST['AVECDO_PREVIOUS_LANG_ID'] : $_POST['AVECDO_LANGUAGE_ID'];
    345 
    346                 $data = isset($multiLangShopData[$langCode]) ? $multiLangShopData[$langCode] : [];
    347                 $newData = [
    348                     'lang_code' => $_POST['AVECDO_LANGUAGE_ID'],
    349                     'currency_id' => $_POST['AVECDO_CURRENCY_ID'],
    350                     'description' => $_POST['use_description']
    351                 ];
    352 
    353                 $multiLangShopData[$_POST['AVECDO_LANGUAGE_ID']] = array_merge($data, $newData);
    354                 if (isset($_POST['AVECDO_PREVIOUS_LANG_ID'])) {
    355                     unset($multiLangShopData[$_POST['AVECDO_PREVIOUS_LANG_ID']]);
    356                 }
    357 
    358                 $this->setWPMLShopOptions($multiLangShopData);
    359             }
     308            // If there is no multi-currency enabled (or it has been disabled),
     309            // use the default woocommerce currency.
     310            Option::update('currency', get_woocommerce_currency());
    360311        }
    361312    }
     
    363314    public function getProducts($page, $limit, $lastRun)
    364315    {
    365         return $this->model->getProducts($page, $limit, $lastRun, $this->getWPMLShopOptions(), $this->getKeySet());
     316        return $this->model->getProducts($page, $limit, $lastRun, $this->getKeySet());
    366317    }
    367318
    368319    public function getCategories()
    369320    {
    370         return $this->model->getCategories($this->getWPMLShopOptions(), $this->getKeySet());
     321        return $this->model->getCategories($this->getKeySet());
    371322    }
    372323
     
    376327    }
    377328
    378     private function activationSubmitted($isMultiLang = false, $formData = array())
     329    private function activationSubmitted()
    379330    {
    380331        $_aak          = @$_POST['avecdo_activation_key'];
     
    387338        }
    388339
    389         if($isMultiLang && $this->checkIfKeyIsUsed($keySet,$isMultiLang,$formData['AVECDO_LANGUAGE_ID']) === true){
    390             $this->messages['error'][] = __('Activation key already used!', 'avecdo-for-woocommerce');
    391             return false;
    392         }
    393 
    394         $this->storeKeys($keySet, $isMultiLang);
     340        $this->storeKeys($keySet);
    395341        $webService = new WebService();
    396342
     
    399345        } catch (AuthException $e) {
    400346
    401             $this->resetSubmitted($isMultiLang ,$_POST);
     347            $this->resetSubmitted();
    402348
    403349            $errorMessage = $e->getMessage();
     
    414360        }
    415361
    416         return $this->activateAvecdo($isMultiLang, $formData);
     362        return $this->activateAvecdo();
    417363    }
    418364
     
    420366     * Set avecdo feed as active
    421367     */
    422     private function activateAvecdo($isMultiLang = false, $formData = array())
    423     {
    424         if ($isMultiLang === false) // Set default options:
    425         {
    426             // Set default options:
    427             Option::update('plugin_activated', 1);
    428             Option::update('use_description', 'any');
    429             Option::update('currency', get_woocommerce_currency());
    430 
    431             global $sitepress;
    432             if ($sitepress) {
    433                 Option::update('language', $sitepress->get_current_language());
    434             }
    435 
    436         } else {
    437             $multiLangShopData = $this->getWPMLShopOptions();
    438             $multiLangShopData[$_POST['AVECDO_LANGUAGE_ID']]['shop_activated'] = 1;
    439             $this->setWPMLShopOptions($multiLangShopData);
     368    private function activateAvecdo()
     369    {
     370        // Set default options:
     371        Option::update('plugin_activated', 1);
     372        Option::update('use_description', 'any');
     373        Option::update('currency', get_woocommerce_currency());
     374
     375        global $sitepress;
     376        if ($sitepress) {
     377            Option::update('language', $sitepress->get_current_language());
    440378        }
    441379
     
    528466     * Reset the plugin and delete private/public keys from the database.
    529467     */
    530     private function resetSubmitted($isMultiLang = false, $formData = array())
    531     {
    532         $skipRest = false;
    533         if($isMultiLang === false){
    534             Option::update('plugin_activated', 0);
    535             Option::update('public_key', '');
    536             Option::update('private_key', '');
    537         } else {
    538             $multiLangShopData = $this->getWPMLShopOptions();
    539             //IF WE'RE RESETTING THE MAIN SHOP, MOVE FIRST MULTI SHOP INTO MAIN SHOP IF WE HAVE A MULTISHOP ELSE RESET COMPLETELY
    540             $mainShopKey = Option::get('public_key') . ';' . Option::get('private_key');
    541 
    542             if(
    543                 $mainShopKey === $formData['avecdo_activation_key'] &&
    544                 $multiLangShopData !== null &&
    545                 count($multiLangShopData) > 0)
    546             {
    547                 $shop = reset($multiLangShopData);
    548                 $shop_code = key($multiLangShopData);
    549                 Option::update('public_key', $shop['public_key']);
    550                 Option::update('private_key', $shop['private_key']);
    551                 Option::update('language', $shop['lang_code']);
    552                 Option::update('currency', $shop['currency_id']);
    553                 Option::update('use_description', $shop['description']);
    554 
    555 
    556                 unset($multiLangShopData[$shop_code]);
    557                 $this->setWPMLShopOptions($multiLangShopData);
    558                 $skipRest = true;
    559             }
    560 
    561             if($multiLangShopData !== null && $skipRest === false) {
    562                 foreach ($multiLangShopData as $code => $shop){
    563                     $key = $shop['public_key'] . ';' . $shop['private_key'];
    564                     if($key === $formData['avecdo_activation_key']){
    565                         unset($multiLangShopData[$code]);
    566                         break;
    567                     }
    568                 }
    569                 $this->setWPMLShopOptions($multiLangShopData);
    570             }
    571 
    572             //NO MORE KEYS!
    573             if($mainShopKey === $formData['avecdo_activation_key'] && count($multiLangShopData) <= 0){
    574                 Option::update('plugin_activated', 0);
    575                 Option::update('public_key', '');
    576                 Option::update('private_key', '');
    577                 Option::update('language', '');
    578                 Option::update('currency', '');
    579                 Option::update('use_description', '');
    580                 Option::update('multi_lang_props', '');
    581             }
    582         }
     468    private function resetSubmitted()
     469    {
     470        Option::update('plugin_activated', 0);
     471        Option::update('public_key', '');
     472        Option::update('private_key', '');
    583473
    584474        $this->messages['success'][] = __('Your avecdo keys have been removed from your shop.', 'avecdo-for-woocommerce');
     
    589479     * @param KeySet $keySet
    590480     */
    591     private function storeKeys(KeySet $keySet, $isMultiLang)
    592     {
    593         if (!$isMultiLang) {
    594             Option::update('public_key', $keySet->getPublicKey());
    595             Option::update('private_key', $keySet->getPrivateKey());
    596         } else {
    597             $multiLangShopData = $this->getWPMLShopOptions();
    598 
    599             // Check if the option ket exists and act according to that
    600             if($multiLangShopData) {
    601                 $multiLangShopData[$_POST['AVECDO_LANGUAGE_ID']] = [
    602                     'public_key' => $keySet->getPublicKey(),
    603                     'private_key' => $keySet->getPrivateKey(),
    604                 ];
    605 
    606                 $this->setWPMLShopOptions($multiLangShopData);
    607             } else {
    608                 $multiLangShopData = [
    609                     $_POST['AVECDO_LANGUAGE_ID'] => [
    610                         'public_key' => $keySet->getPublicKey(),
    611                         'private_key' => $keySet->getPrivateKey(),
    612                     ]
    613                 ];
    614                 $this->setWPMLShopOptions($multiLangShopData);
    615             }
    616         }
     481    private function storeKeys(KeySet $keySet)
     482    {
     483        Option::update('public_key', $keySet->getPublicKey());
     484        Option::update('private_key', $keySet->getPrivateKey());
     485
    617486        // load keyset.
    618487        $this->keySet = null;
     
    643512                $this->keySet = new KeySet($publicKey, Option::get('private_key'));
    644513            }
    645             else {
    646                 $multiLangShopData = $this->getWPMLShopOptions();
    647                 if(!empty($multiLangShopData)) {
    648                     foreach ($multiLangShopData as $code => $shop) {
    649                         if ($shop['public_key'] === $headers['x-apikey']) {
    650                             $this->keySet = new KeySet($shop['public_key'], $shop['private_key']);
    651                             break;
    652                         }
    653                     }
    654                 }
    655 
    656                 if($this->keySet === null){
    657                     $this->keySet = new KeySet($publicKey, Option::get('private_key'));
    658                 }
     514            elseif($this->keySet === null){
     515                $this->keySet = new KeySet($publicKey, Option::get('private_key'));
    659516            }
    660517        } else {
     
    662519        }
    663520    }
    664 
    665     public function checkIfKeyIsUsed(KeySet $keySet, $isMultiLang = false, $language_code = null){
    666         if($isMultiLang === true){
    667             $used = false;
    668             $mainShopKey = Option::get('public_key') . ';' . Option::get('private_key');
    669             $formKey = $keySet->getPublicKey().';'.$keySet->getPrivateKey();
    670             if($mainShopKey === $formKey){
    671                 $used = true;
    672             }
    673 
    674             $multiLangShopData = $this->getWPMLShopOptions();
    675             if ($multiLangShopData !== null && $used === false) {
    676                 foreach ($multiLangShopData as $code => $shop){
    677                     if(
    678                         $code !== $language_code &&
    679                         $shop['public_key'] === $keySet->getPublicKey() &&
    680                         $shop['private_key'] === $keySet->getPrivateKey()
    681                     ){
    682                         $used = true;
    683                     }
    684                 }
    685             }
    686         } else {
    687             $used = false;
    688         }
    689 
    690         return $used;
    691     }
    692 
    693521
    694522    /**
  • avecdo-for-woocommerce/trunk/src/Models/Model.php

    r3463216 r3484553  
    4040    {
    4141        parent::__construct();
    42     }
    43 
    44     // @todo check if wee need this for products thats set to allow back orders
    45     private function assignAvecdoProductStock($productId, $avecdoProduct)
    46     {
    47         //
    48         // Works fine but we do not set default stock value
    49         // so no need for extra sql calls
    50         //
    51         //$productId = (int)$productId;
    52         //global $wpdb;
    53         //$meta_query   = "SELECT
    54         //                     t1.post_id,
    55         //                     t1.meta_value as stock,
    56         //                     t2.meta_value as backorders,
    57         //                     t3.meta_value as manage_stock
    58         //                FROM ". $wpdb->prefix ."postmeta AS t1
    59         //                INNER JOIN  ". $wpdb->prefix ."postmeta AS t2
    60         //                ON          t2.post_id=t1.post_id
    61         //                AND         t2.meta_key='_backorders'
    62         //
    63         //                INNER JOIN  ". $wpdb->prefix ."postmeta AS t3
    64         //                ON          t3.post_id=t1.post_id
    65         //                AND         t3.meta_key='_manage_stock'
    66         //
    67         //                WHERE t1.post_id = {$productId}
    68         //                AND   t1.meta_key='_stock'";
    69         //if($query_result = $wpdb->get_results($meta_query, OBJECT)) {
    70         //    $query_result = $query_result[0];
    71         //
    72         //    $avecdoProduct->setStockQuantity($query_result->stock);
    73         //    if((int)$query_result->stock<=0 && $query_result->manage_stock == "no") {
    74         //        /* if the shop do not manage stock then set default of 20. */
    75         //        $avecdoProduct->setStockQuantity(20);
    76         //    } else if((int)$query_result->stock<=0 && $query_result->backorders != "no") {
    77         //        /* if the shop manage stock but allow backorders then set default of 20. */
    78         //        $avecdoProduct->setStockQuantity(20);
    79         //    }
    80         //}
    8142    }
    8243
     
    284245                case "_wp_old_slug":
    285246                case "_wp_page_template":
    286                     /* @todo see 'assignAvecdoProductStock' */
    287247                case "_backorders":
    288248                case "_manage_stock":
     
    458418                    $avecdoProduct->{$method}($metaValue);
    459419                }
    460                 // @todo see 'assignAvecdoProductStock'
    461                 if (strpos($method, 'Quantity') !== false) {
    462                     $this->assignAvecdoProductStock($productId, $avecdoProduct);
    463                 }
    464420            }
    465421        }
     
    486442    }
    487443
    488     public function getProducts($page, $limit, $lastRun, $multiLanguageOptions = null, $activeKey = null)
     444    public function getProducts($page, $limit, $lastRun, $activeKey = null)
    489445    {
    490446        $offset   = ((((int) $page == 0 ? 1 : (int) $page) - 1) * (int) $limit);
    491447        $products = array();
    492448
    493         $shopCurrencyLanguageSettings = $this->getMultiLangOptions($multiLanguageOptions,$activeKey);
     449        $shopCurrencyLanguageSettings = $this->getMultiLangOptions($activeKey);
    494450        $_language  = $shopCurrencyLanguageSettings['language'];
    495451        $_currency  = $shopCurrencyLanguageSettings['currency'];
     
    955911        $tagIds      = array();
    956912        $this->assignAvecdoProductCategoriesAndTags($parentProductId, $avecdoProduct, $categoryIds, $tagIds);
    957 
    958 
    959         /* Removed for now avecdo do not use this value so spare the resources... */
    960 //        // related products
    961 //        foreach ($this->getRelatedProductsByCategoriesAndTags($categoryIds, $tagIds) as $relatedProduct) {
    962 //            if ($relatedProduct->productId == $productId) {
    963 //                continue;
    964 //            }
    965 //            $avecdoProduct->addToRelatedProducts($relatedProduct->productId, $relatedProduct->name);
    966 //        }
    967913    }
    968914
     
    12911237     * @return array
    12921238     */
    1293     public function getCategories($multiLanguageOptions = null, $activeKey = null)
     1239    public function getCategories($activeKey = null)
    12941240    {
    12951241        $hasMultiCurrency = $this->isMultiCurrencyEnabled();
    12961242
    1297         $shopCurrencyLanguageSettings = $this->getMultiLangOptions($multiLanguageOptions,$activeKey);
     1243        $shopCurrencyLanguageSettings = $this->getMultiLangOptions($activeKey);
    12981244        $_language  = $shopCurrencyLanguageSettings['language'];
    12991245
     
    13641310    }
    13651311
    1366     public function getMultiLangOptions($multiLanguageOptions = null, $activeKey = null) {
    1367         if($multiLanguageOptions !== null && $activeKey !== null){
    1368             $publicKey = $activeKey->getPublicKey();
    1369             foreach($multiLanguageOptions as $code => $shop){
    1370                 if($shop['public_key'] === $publicKey){
    1371                     $_currency = $shop['currency_id'];
    1372                     $_language = $shop['lang_code'];
    1373                     break;
    1374                 }
    1375             }
    1376         }
    1377 
     1312    public function getMultiLangOptions($activeKey = null) {
     1313        // Handle multilang options
    13781314        if ($activeKey && Option::isJson($publicKey = Option::get('public_key'))) {
    13791315            $publicKeys = json_decode($publicKey, true);
  • avecdo-for-woocommerce/trunk/src/Models/WooQueries.php

    r2948430 r3484553  
    2424        $this->wpdb        = $wpdb;
    2525        $this->wpdb_prefix = $wpdb->prefix;
    26     }
    27 
    28     /**
    29      * Gets a boolean value indicating if the product has any children
    30      * @param int $productId
    31      * @return boolean
    32      * @author Christian M. Jensen <christian@modified.dk>
    33      * @since 1.2.3
    34      * @deprecated since v1.2.5 not reliable since WooCommerce '3.1.2'
    35      *
    36      * ------
    37      *
    38      * In WooCommerce '3.1.2', this returns a minimum of one id for all products,
    39      * so it is not reliable, use the following to check, for children
    40      *
    41      * $productId = 78;
    42      * $productVairations = $this->getProductVairationsByProductId((int) $productId);
    43      *
    44      * if(count($productVairations)>0) {
    45      *      // product has vairations.
    46      * }
    47      *
    48      * ------
    49      */
    50     protected function hasChildren($productId)
    51     {
    52         $productId = (int) $productId;
    53         if ($productId <= 0) {
    54             return false;
    55         }
    56         $query        = "SELECT ID FROM ".$this->wpdb_prefix."posts WHERE post_parent={$productId} LIMIT 1";
    57         $query_result = $this->wpdb->get_results($query, OBJECT);
    58         return $query_result ? true : false;
    59     }
    60     /**
    61      * Alias of 'hasChildren'
    62      * @deprecated since v1.2.3, miss spelled. Use: 'hasChildren'
    63      * @param int $productId
    64      * @return boolean
    65      * @author Christian M. Jensen <christian@modified.dk>
    66      * @since 1.1.2
    67      */
    68     protected function hasChilden($productId)
    69     {
    70         return $this->hasChildren($productId);
    7126    }
    7227
     
    151106        self::$_sttributeTaxonomyCache[$name] = $query_result ? $query_result : array();
    152107        return self::$_sttributeTaxonomyCache[$name];
    153     }
    154 
    155     /**
    156      * Get related products by tags
    157      * @param int[] $tagIds
    158      * @param int $limit
    159      * @param int $offset
    160      * @return \stdClass[] [productId, name]
    161      * @author Christian M. Jensen <christian@modified.dk>
    162      * @since 1.1.2
    163      */
    164     protected function getRelatedProductsByTags(array $tagIds, $limit = 5, $offset = 0)
    165     {
    166         if (empty($tagIds)) {
    167             return array();
    168         }
    169         $tags = implode(',', array_map('intval', $tagIds));
    170         $tags = trim($tags);
    171         if (empty($tags)) {
    172             return array();
    173         }
    174         $query        = "SELECT ".$this->wpdb_prefix."posts.ID AS productId, ".$this->wpdb_prefix."posts.post_title AS name FROM ".$this->wpdb_prefix."posts
    175         INNER JOIN ".$this->wpdb_prefix."term_relationships AS tt1 ON ".$this->wpdb_prefix."posts.ID = tt1.object_id
    176         INNER JOIN ".$this->wpdb_prefix."postmeta ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."postmeta.post_id
    177         WHERE tt1.term_taxonomy_id IN ({$tags})
    178         AND ".$this->wpdb_prefix."posts.post_type = 'product'
    179         AND ".$this->wpdb_prefix."posts.post_status = 'publish'
    180         AND ".$this->wpdb_prefix."postmeta.meta_key = '_visibility'
    181         AND CAST(".$this->wpdb_prefix."postmeta.meta_value AS CHAR) IN ('visible','catalog')
    182         GROUP BY ".$this->wpdb_prefix."posts.ID ORDER BY ".$this->wpdb_prefix."posts.ID DESC LIMIT {$offset}, {$limit}";
    183         $query_result = $this->wpdb->get_results($query, OBJECT);
    184         return $query_result ? $query_result : array();
    185     }
    186 
    187     /**
    188      * Get related products by categories
    189      * @param int[] $categoryIds
    190      * @param int $limit
    191      * @param int $offset
    192      * @return \stdClass[] [productId, name]
    193      * @author Christian M. Jensen <christian@modified.dk>
    194      * @since 1.1.2
    195      */
    196     protected function getRelatedProductsByCategories(array $categoryIds, $limit = 6, $offset = 0)
    197     {
    198         if (empty($categoryIds)) {
    199             return array();
    200         }
    201         $categoris = implode(',', array_map('intval', $categoryIds));
    202         $categoris = trim($categoris);
    203         if (empty($categoris)) {
    204             return array();
    205         }
    206         $query        = "SELECT ".$this->wpdb_prefix."posts.ID AS productId, ".$this->wpdb_prefix."posts.post_title AS name FROM ".$this->wpdb_prefix."posts
    207         INNER JOIN ".$this->wpdb_prefix."term_relationships AS tt1 ON ".$this->wpdb_prefix."posts.ID = tt1.object_id
    208         INNER JOIN ".$this->wpdb_prefix."postmeta ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."postmeta.post_id
    209         WHERE tt1.term_taxonomy_id IN ({$categoris})
    210         AND ".$this->wpdb_prefix."posts.post_type = 'product'
    211         AND ".$this->wpdb_prefix."posts.post_status = 'publish'
    212         AND ".$this->wpdb_prefix."postmeta.meta_key = '_visibility'
    213         AND CAST(".$this->wpdb_prefix."postmeta.meta_value AS CHAR) IN ('visible','catalog')
    214         GROUP BY ".$this->wpdb_prefix."posts.ID ORDER BY ".$this->wpdb_prefix."posts.ID DESC LIMIT {$offset}, {$limit}";
    215         $query_result = $this->wpdb->get_results($query, OBJECT);
    216         return $query_result ? $query_result : array();
    217     }
    218 
    219     /**
    220      * Get related products by categories and tags
    221      * @param int[] $categoryIds
    222      * @param int[] $tagIds
    223      * @param int $limit
    224      * @param int $offset
    225      * @return \stdClass[] [productId, name]
    226      * @author Christian M. Jensen <christian@modified.dk>
    227      * @since 1.1.2
    228      */
    229     protected function getRelatedProductsByCategoriesAndTags(array $categoryIds, array $tagIds, $limit = 6, $offset = 0)
    230     {
    231         $categoryQuery = "";
    232         if (!empty($categoryIds)) {
    233             $categoryQuery .= "".$this->wpdb_prefix."term_relationships.term_taxonomy_id IN (".implode(',', array_map('intval', $categoryIds)).")";
    234         }
    235         $tagQuery = "";
    236         if (!empty($tagIds)) {
    237             $tagQuery .= "tt1.term_taxonomy_id IN (".implode(',', array_map('intval', $tagIds)).")";
    238         }
    239         $exQuery = "";
    240         if (!empty($tagQuery) && !empty($categoryQuery)) {
    241             $exQuery = "({$categoryQuery} OR {$tagQuery}) AND";
    242         } else if (empty($tagQuery) && !empty($categoryQuery)) {
    243             $exQuery = "({$categoryQuery}) AND";
    244         } else if (!empty($tagQuery) && empty($categoryQuery)) {
    245             $exQuery = "({$tagQuery}) AND";
    246         }
    247 
    248         $query        = "SELECT ".$this->wpdb_prefix."posts.ID AS productId, ".$this->wpdb_prefix."posts.post_title AS name FROM ".$this->wpdb_prefix."posts
    249         INNER JOIN ".$this->wpdb_prefix."term_relationships ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."term_relationships.object_id
    250         INNER JOIN ".$this->wpdb_prefix."term_relationships AS tt1 ON ".$this->wpdb_prefix."posts.ID = tt1.object_id
    251         INNER JOIN ".$this->wpdb_prefix."postmeta ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."postmeta.post_id
    252         WHERE ".$exQuery." ".$this->wpdb_prefix."posts.post_type = 'product'
    253         AND ".$this->wpdb_prefix."posts.post_status = 'publish'
    254         AND ".$this->wpdb_prefix."postmeta.meta_key = '_visibility'
    255         AND CAST(".$this->wpdb_prefix."postmeta.meta_value AS CHAR) IN ('visible','catalog')
    256         GROUP BY ".$this->wpdb_prefix."posts.ID ORDER BY ".$this->wpdb_prefix."posts.ID DESC LIMIT {$offset}, {$limit}";
    257         $query_result = $this->wpdb->get_results($query, OBJECT);
    258         return $query_result ? $query_result : array();
    259     }
    260 
    261     /**
    262      * Get related products by product id(s)
    263      * @param int[] $productIds
    264      * @param int $limit
    265      * @param int $offset
    266      * @return \stdClass[] [productId, name]
    267      * @author Christian M. Jensen <christian@modified.dk>
    268      * @since 1.1.2
    269      */
    270     protected function getRelatedProductsByProductIds(array $productIds, $limit = 6, $offset = 0)
    271     {
    272         $query        = "SELECT ".$this->wpdb_prefix."posts.ID AS productId, ".$this->wpdb_prefix."posts.post_title AS name FROM ".$this->wpdb_prefix."posts
    273         INNER JOIN ".$this->wpdb_prefix."term_relationships ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."term_relationships.object_id
    274         INNER JOIN ".$this->wpdb_prefix."term_relationships AS tt1 ON ".$this->wpdb_prefix."posts.ID = tt1.object_id
    275         INNER JOIN ".$this->wpdb_prefix."postmeta ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."postmeta.post_id
    276         WHERE (
    277             ".$this->wpdb_prefix."term_relationships.term_taxonomy_id IN (
    278                 SELECT t.term_id FROM ".$this->wpdb_prefix."terms AS t
    279                 INNER JOIN ".$this->wpdb_prefix."term_taxonomy AS tt ON tt.term_id = t.term_id
    280                 INNER JOIN ".$this->wpdb_prefix."term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
    281                 WHERE tt.taxonomy IN ('product_cat') AND tr.object_id IN
    282                                 (".implode(',', array_map('intval', $productIds)).") ORDER BY t.term_id ASC
    283             ) OR tt1.term_taxonomy_id IN (
    284                 SELECT t.term_id FROM ".$this->wpdb_prefix."terms AS t
    285                 INNER JOIN ".$this->wpdb_prefix."term_taxonomy AS tt ON tt.term_id = t.term_id
    286                                 INNER JOIN ".$this->wpdb_prefix."term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
    287                                 WHERE tt.taxonomy IN ('product_tag') AND tr.object_id IN
    288                                 (".implode(',', array_map('intval', $productIds)).") ORDER BY t.term_id ASC
    289             )
    290         )
    291         AND ".$this->wpdb_prefix."posts.post_type = 'product'
    292         AND ".$this->wpdb_prefix."posts.post_status = 'publish'
    293         AND ".$this->wpdb_prefix."postmeta.meta_key = '_visibility'
    294         AND CAST(".$this->wpdb_prefix."postmeta.meta_value AS CHAR) IN ('visible','catalog')
    295         GROUP BY ".$this->wpdb_prefix."posts.ID ORDER BY ".$this->wpdb_prefix."posts.ID DESC LIMIT {$offset}, {$limit}";
    296         $query_result = $this->wpdb->get_results($query, OBJECT);
    297         return $query_result ? $query_result : array();
    298     }
    299 
    300     /**
    301      * Get all categories for products by product id.
    302      * @param int[] $productIds
    303      * @return \stdClass[] [term_id, name]
    304      * @author Christian M. Jensen <christian@modified.dk>
    305      * @since 1.1.2
    306      */
    307     protected function getProductCategories(array $productIds)
    308     {
    309         $query        = "SELECT t.*, tt.* FROM ".$this->wpdb_prefix."terms AS t
    310             INNER JOIN ".$this->wpdb_prefix."term_taxonomy AS tt ON tt.term_id = t.term_id
    311             INNER JOIN ".$this->wpdb_prefix."term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
    312             WHERE tt.taxonomy IN ('product_cat') AND tr.object_id IN (".implode(',', array_map('intval', $productIds)).") ORDER BY t.name ASC";
    313         $query_result = $this->wpdb->get_results($query, OBJECT);
    314         return $query_result ? $query_result : array();
    315     }
    316 
    317     /**
    318      * Get all tags for products by product id.
    319      * @param int[] $productIds
    320      * @return \stdClass[] [term_id, name]
    321      * @author Christian M. Jensen <christian@modified.dk>
    322      * @since 1.1.2
    323      */
    324     protected function getProductTags(array $productIds)
    325     {
    326         $query        = "SELECT t.term_id, t.name FROM ".$this->wpdb_prefix."terms AS t
    327           INNER JOIN ".$this->wpdb_prefix."term_taxonomy AS tt ON tt.term_id = t.term_id INNER
    328           JOIN ".$this->wpdb_prefix."term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
    329           WHERE tt.taxonomy IN ('product_tag') AND tr.object_id IN (".implode(',', array_map('intval', $productIds)).") ORDER BY t.name ASC";
    330         $query_result = $this->wpdb->get_results($query, OBJECT);
    331         return $query_result ? $query_result : array();
    332108    }
    333109
     
    503279
    504280    /**
    505      * get images meta data [post_id, file, meta, image_alt]
    506      * @param int[] $imagesIds
    507      * @return \stdClass[]
    508      * @author Christian M. Jensen <christian@modified.dk>
    509      * @since 1.1.2
    510      */
    511     protected function getImagesData($imagesIds)
    512     {
    513         $query  = "SELECT t1.post_id, t1.meta_value as file, t2.meta_value as meta, t3.post_title as image_alt
    514                        FROM ".$this->wpdb_prefix."postmeta AS t1
    515                        INNER JOIN ".$this->wpdb_prefix."postmeta AS t2
    516                        ON t2.post_id=t1.post_id
    517                        AND t2.meta_key='_wp_attachment_metadata'
    518                        LEFT JOIN ".$this->wpdb_prefix."posts AS t3
    519                        ON t3.ID=t1.post_id AND t3.post_type='attachment'
    520                        WHERE t1.post_id IN (".implode(',', array_map('intval', $imagesIds)).")
    521                        AND t1.meta_key='_wp_attached_file'";
    522         $result = $this->wpdb->get_results($query, OBJECT);
    523         return $result ? $result : array();
    524     }
    525 
    526     /**
    527281     * Get WooCommerce instance
    528282     * @global array $GLOBALS
  • avecdo-for-woocommerce/trunk/views/activated.php

    r3463216 r3484553  
    11<?php
    2 if (isset($mesages) && count($mesages) > 0):
    3     foreach ($mesages as $type => $mesage):
    4         avecdoEchoNotice(implode('<br>', $mesage), $type, true);
     2if (isset($messages) && count($messages) > 0):
     3    foreach ($messages as $type => $message):
     4        avecdoEchoNotice(implode('<br>', $message), $type, true);
    55    endforeach;
    66endif;
    77$nonce = wp_create_nonce('avecdo_activation_form');
    8 $isVersion1 = $versionSelected == 1;
    9 ?>
    10 
    11 <?php
    12 // end of multi currency
    13 
    148?>
    159<div class="avecdo-wrapper">
    1610    <div class="avecdo-content">
    1711        <div class="avecdo-spacer-l"></div>
    18         <?php include 'version-selector.php' ?>
    1912        <div class="avecdo-box-notop">
    20             <?php if ($isVersion1 || !$multiCurrencyEnabled) : ?>
     13            <?php if (!$multiCurrencyEnabled) : ?>
    2114                <div class="avecdo-align-left">
    2215                    <h2 class="avecdo-shop-connected"><?php echo __('Your shop is connected.', 'avecdo-for-woocommerce'); ?></h2>
     
    2720            </div>
    2821
    29             <?php if ($isVersion1 || !$multiCurrencyEnabled) : ?>
     22            <?php if (!$multiCurrencyEnabled) : ?>
    3023                <div class="avecdo-inner-container">
    3124                    <form method="post" action="<?php echo admin_url('admin.php?page=avecdo&activation=true'); ?>">
  • avecdo-for-woocommerce/trunk/views/index.php

    r3463216 r3484553  
    11<div class="avecdo-wrapper">
    22    <?php
    3     if (isset($mesages) && count($mesages) > 0):
    4         foreach ($mesages as $type => $mesage):
    5             avecdoEchoNotice(implode('<br>', $mesage), $type, true);
     3    if (isset($messages) && count($messages) > 0):
     4        foreach ($messages as $type => $message):
     5            avecdoEchoNotice(implode('<br>', $message), $type, true);
    66        endforeach;
    77    endif;
     
    2828        <div class="avecdo-content">
    2929            <div class="activation-flow"></div>
    30             <?php include 'version-selector.php' ?>
    3130            <div class="avecdo-box-notop">
    3231                <div class="avecdo-align-left">
     
    3837                <div class="avecdo-spacer-s"></div>
    3938                <div>
    40                     <?php if ($versionSelected == 1 || !$multiCurrencyEnabled || empty($languages)): ?>
     39                    <?php if (!$multiCurrencyEnabled || empty($languages)): ?>
    4140                        <form method="post" action="<?php echo admin_url('admin.php?page=avecdo&activation=true'); ?>">
    4241                            <input type="hidden" name="avecdo_submit_activation" value="1" />
Note: See TracChangeset for help on using the changeset viewer.