Changeset 3484553
- Timestamp:
- 03/17/2026 08:24:51 AM (3 weeks ago)
- Location:
- avecdo-for-woocommerce/trunk
- Files:
-
- 2 deleted
- 8 edited
-
avecdo.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
-
src/Classes/FeedLoader.php (deleted)
-
src/Classes/Option.php (modified) (1 diff)
-
src/Classes/Plugin.php (modified) (19 diffs)
-
src/Models/Model.php (modified) (7 diffs)
-
src/Models/WooQueries.php (modified) (3 diffs)
-
views/activated.php (modified) (2 diffs)
-
views/index.php (modified) (3 diffs)
-
views/version-selector.php (deleted)
Legend:
- Unmodified
- Added
- Removed
-
avecdo-for-woocommerce/trunk/avecdo.php
r3463216 r3484553 4 4 * Plugin URI: https://avecdo.com/ 5 5 * Description: avecdo connector plugin for WooCommerce 6 * Version: 1.8. 06 * Version: 1.8.1 7 7 * Author: Modified Solutions ApS 8 8 * Author URI: https://www.modified.dk/ … … 10 10 * Developer URI: https://www.modified.dk/ 11 11 * Requires at least: 4.5 12 * Tested up to: 6.9. 112 * Tested up to: 6.9.4 13 13 * WC requires at least: 2.6.0 14 * WC tested up to: 8.1.114 * WC tested up to: 10.5.1 15 15 * 16 16 * Text Domain: avecdo-for-woocommerce … … 34 34 * @var string Version string 35 35 */ 36 define('AVECDO_WOOCOMMERCE_PLUGIN_VERSION', '1.8. 0');36 define('AVECDO_WOOCOMMERCE_PLUGIN_VERSION', '1.8.1'); 37 37 38 38 /** … … 50 50 $avecdoPlugin->loadTextdomain(); 51 51 $avecdoPlugin->registerPluginActions(); 52 53 add_option('avecdo_version', 1);54 52 55 53 /* … … 80 78 $plugin->render(); 81 79 } 82 83 84 85 80 86 81 if (!function_exists('avecdo_safe_redirect')) { … … 197 192 } 198 193 199 if (!function_exists('avecdoValidateWooCommerceVersion')) {200 201 /**202 * Validate the current WooCommerce version203 *204 * @staticvar type $wooCommerceVersion205 * @staticvar array $cachedVersionCompare206 * @param type $version207 * @param type $operator208 * @return boolean209 * @author Christian M. Jensen <christian@modified.dk>210 * @since 1.1.2211 */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 $metadata239 * @param string $imagealt240 * @return string defaults to $imagealt241 */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 folder269 * @param file $file270 * @return string271 * @author Christian M. Jensen <christian@modified.dk>272 * @since 1.1.2273 */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 $file293 * @param string $file partial path to file.294 * @param int $fileId database id of the file295 * @return string296 * @author Christian M. Jensen <christian@modified.dk>297 * @since 1.1.2298 */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 table330 * @global wpdb $wpdb331 * @param int $fileId332 * @return string333 * @author Christian M. Jensen <christian@modified.dk>334 * @since 1.1.2335 */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 347 194 // Set WooCommerce HPOS compatibility 348 195 add_action( 'before_woocommerce_init', function() { -
avecdo-for-woocommerce/trunk/readme.txt
r3463216 r3484553 3 3 Tags: feed, service, avecdo, Facebook, Google Shopping, shopping, woocommerce, kelkoo, miinto, Pricerunner, Partner-ads, ecommerce, e-commerce 4 4 Requires at least: 4.5 5 Tested up to: 6.9. 16 Stable tag: 1.8. 05 Tested up to: 6.9.4 6 Stable tag: 1.8.1 7 7 License: Mozilla Public License Version 2.0 8 8 License URI: https://www.mozilla.org/en-US/MPL/2.0/ … … 45 45 46 46 == Changelog == 47 48 = 1.8.1 = 49 * Remove unused code and files 50 * Updated tested up to version 6.9.4 47 51 48 52 = 1.8.0 = -
avecdo-for-woocommerce/trunk/src/Classes/Option.php
r3463216 r3484553 98 98 private static function getFullName($name) 99 99 { 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; 123 101 } 124 102 } -
avecdo-for-woocommerce/trunk/src/Classes/Plugin.php
r3463216 r3484553 24 24 const WOOCOMMERCE_NOT_ACTIVE = 'WooCommerce is not activated.'; 25 25 const NOT_SUFFICIENT_PERMISSIONS = 'You do not have sufficient permissions to access this page.'; 26 const ERROR_CODE_INTERFACE = 6872;27 26 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.'; 28 27 … … 153 152 } 154 153 155 public function prepareMultiCurrency( $multiCurrencyEnabled,&$languages, &$currencies)154 public function prepareMultiCurrency(&$languages, &$currencies) 156 155 { 157 156 // 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; 176 173 } 177 174 } … … 205 202 } 206 203 207 $this->prepareMultiCurrency( $multiCurrencyEnabled,$languages, $currencies);204 $this->prepareMultiCurrency( $languages, $currencies); 208 205 209 206 if (empty($languages)) { … … 216 213 217 214 $activationKey = $this->keySet->asString(); 218 $mes ages = $this->messages;215 $messages = $this->messages; 219 216 $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'])) { 223 219 $activation = true; 224 220 } … … 232 228 $content = ob_get_clean(); 233 229 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));246 230 } 247 231 … … 298 282 { 299 283 if ($_SERVER['REQUEST_METHOD'] === 'POST') { 300 301 284 if (isset($_POST['avecdo_lang_settings'])) { 302 285 $this->handleWPMLSettings(); … … 304 287 } 305 288 306 $isMultiLang = false;307 if (isset($_POST['avecdo_multi_lang']) && $_POST['avecdo_multi_lang'] === '1') {308 $isMultiLang = true;309 }310 311 289 if (isset($_POST['avecdo_submit_activation'])) { 312 $activated = $this->activationSubmitted( $isMultiLang, $_POST);290 $activated = $this->activationSubmitted(); 313 291 if (!$activated) { 314 292 return; … … 316 294 317 295 } 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 { 321 298 $this->updateKeySet(); 322 299 } … … 329 306 Option::update('use_description', $_POST['use_description']); 330 307 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()); 360 311 } 361 312 } … … 363 314 public function getProducts($page, $limit, $lastRun) 364 315 { 365 return $this->model->getProducts($page, $limit, $lastRun, $this->get WPMLShopOptions(), $this->getKeySet());316 return $this->model->getProducts($page, $limit, $lastRun, $this->getKeySet()); 366 317 } 367 318 368 319 public function getCategories() 369 320 { 370 return $this->model->getCategories($this->get WPMLShopOptions(), $this->getKeySet());321 return $this->model->getCategories($this->getKeySet()); 371 322 } 372 323 … … 376 327 } 377 328 378 private function activationSubmitted( $isMultiLang = false, $formData = array())329 private function activationSubmitted() 379 330 { 380 331 $_aak = @$_POST['avecdo_activation_key']; … … 387 338 } 388 339 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); 395 341 $webService = new WebService(); 396 342 … … 399 345 } catch (AuthException $e) { 400 346 401 $this->resetSubmitted( $isMultiLang ,$_POST);347 $this->resetSubmitted(); 402 348 403 349 $errorMessage = $e->getMessage(); … … 414 360 } 415 361 416 return $this->activateAvecdo( $isMultiLang, $formData);362 return $this->activateAvecdo(); 417 363 } 418 364 … … 420 366 * Set avecdo feed as active 421 367 */ 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()); 440 378 } 441 379 … … 528 466 * Reset the plugin and delete private/public keys from the database. 529 467 */ 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', ''); 583 473 584 474 $this->messages['success'][] = __('Your avecdo keys have been removed from your shop.', 'avecdo-for-woocommerce'); … … 589 479 * @param KeySet $keySet 590 480 */ 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 617 486 // load keyset. 618 487 $this->keySet = null; … … 643 512 $this->keySet = new KeySet($publicKey, Option::get('private_key')); 644 513 } 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')); 659 516 } 660 517 } else { … … 662 519 } 663 520 } 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 693 521 694 522 /** -
avecdo-for-woocommerce/trunk/src/Models/Model.php
r3463216 r3484553 40 40 { 41 41 parent::__construct(); 42 }43 44 // @todo check if wee need this for products thats set to allow back orders45 private function assignAvecdoProductStock($productId, $avecdoProduct)46 {47 //48 // Works fine but we do not set default stock value49 // so no need for extra sql calls50 //51 //$productId = (int)$productId;52 //global $wpdb;53 //$meta_query = "SELECT54 // t1.post_id,55 // t1.meta_value as stock,56 // t2.meta_value as backorders,57 // t3.meta_value as manage_stock58 // FROM ". $wpdb->prefix ."postmeta AS t159 // INNER JOIN ". $wpdb->prefix ."postmeta AS t260 // ON t2.post_id=t1.post_id61 // AND t2.meta_key='_backorders'62 //63 // INNER JOIN ". $wpdb->prefix ."postmeta AS t364 // ON t3.post_id=t1.post_id65 // 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 //}81 42 } 82 43 … … 284 245 case "_wp_old_slug": 285 246 case "_wp_page_template": 286 /* @todo see 'assignAvecdoProductStock' */287 247 case "_backorders": 288 248 case "_manage_stock": … … 458 418 $avecdoProduct->{$method}($metaValue); 459 419 } 460 // @todo see 'assignAvecdoProductStock'461 if (strpos($method, 'Quantity') !== false) {462 $this->assignAvecdoProductStock($productId, $avecdoProduct);463 }464 420 } 465 421 } … … 486 442 } 487 443 488 public function getProducts($page, $limit, $lastRun, $ multiLanguageOptions = null, $activeKey = null)444 public function getProducts($page, $limit, $lastRun, $activeKey = null) 489 445 { 490 446 $offset = ((((int) $page == 0 ? 1 : (int) $page) - 1) * (int) $limit); 491 447 $products = array(); 492 448 493 $shopCurrencyLanguageSettings = $this->getMultiLangOptions($ multiLanguageOptions,$activeKey);449 $shopCurrencyLanguageSettings = $this->getMultiLangOptions($activeKey); 494 450 $_language = $shopCurrencyLanguageSettings['language']; 495 451 $_currency = $shopCurrencyLanguageSettings['currency']; … … 955 911 $tagIds = array(); 956 912 $this->assignAvecdoProductCategoriesAndTags($parentProductId, $avecdoProduct, $categoryIds, $tagIds); 957 958 959 /* Removed for now avecdo do not use this value so spare the resources... */960 // // related products961 // foreach ($this->getRelatedProductsByCategoriesAndTags($categoryIds, $tagIds) as $relatedProduct) {962 // if ($relatedProduct->productId == $productId) {963 // continue;964 // }965 // $avecdoProduct->addToRelatedProducts($relatedProduct->productId, $relatedProduct->name);966 // }967 913 } 968 914 … … 1291 1237 * @return array 1292 1238 */ 1293 public function getCategories($ multiLanguageOptions = null, $activeKey = null)1239 public function getCategories($activeKey = null) 1294 1240 { 1295 1241 $hasMultiCurrency = $this->isMultiCurrencyEnabled(); 1296 1242 1297 $shopCurrencyLanguageSettings = $this->getMultiLangOptions($ multiLanguageOptions,$activeKey);1243 $shopCurrencyLanguageSettings = $this->getMultiLangOptions($activeKey); 1298 1244 $_language = $shopCurrencyLanguageSettings['language']; 1299 1245 … … 1364 1310 } 1365 1311 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 1378 1314 if ($activeKey && Option::isJson($publicKey = Option::get('public_key'))) { 1379 1315 $publicKeys = json_decode($publicKey, true); -
avecdo-for-woocommerce/trunk/src/Models/WooQueries.php
r2948430 r3484553 24 24 $this->wpdb = $wpdb; 25 25 $this->wpdb_prefix = $wpdb->prefix; 26 }27 28 /**29 * Gets a boolean value indicating if the product has any children30 * @param int $productId31 * @return boolean32 * @author Christian M. Jensen <christian@modified.dk>33 * @since 1.2.334 * @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 children40 *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 $productId64 * @return boolean65 * @author Christian M. Jensen <christian@modified.dk>66 * @since 1.1.267 */68 protected function hasChilden($productId)69 {70 return $this->hasChildren($productId);71 26 } 72 27 … … 151 106 self::$_sttributeTaxonomyCache[$name] = $query_result ? $query_result : array(); 152 107 return self::$_sttributeTaxonomyCache[$name]; 153 }154 155 /**156 * Get related products by tags157 * @param int[] $tagIds158 * @param int $limit159 * @param int $offset160 * @return \stdClass[] [productId, name]161 * @author Christian M. Jensen <christian@modified.dk>162 * @since 1.1.2163 */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."posts175 INNER JOIN ".$this->wpdb_prefix."term_relationships AS tt1 ON ".$this->wpdb_prefix."posts.ID = tt1.object_id176 INNER JOIN ".$this->wpdb_prefix."postmeta ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."postmeta.post_id177 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 categories189 * @param int[] $categoryIds190 * @param int $limit191 * @param int $offset192 * @return \stdClass[] [productId, name]193 * @author Christian M. Jensen <christian@modified.dk>194 * @since 1.1.2195 */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."posts207 INNER JOIN ".$this->wpdb_prefix."term_relationships AS tt1 ON ".$this->wpdb_prefix."posts.ID = tt1.object_id208 INNER JOIN ".$this->wpdb_prefix."postmeta ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."postmeta.post_id209 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 tags221 * @param int[] $categoryIds222 * @param int[] $tagIds223 * @param int $limit224 * @param int $offset225 * @return \stdClass[] [productId, name]226 * @author Christian M. Jensen <christian@modified.dk>227 * @since 1.1.2228 */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."posts249 INNER JOIN ".$this->wpdb_prefix."term_relationships ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."term_relationships.object_id250 INNER JOIN ".$this->wpdb_prefix."term_relationships AS tt1 ON ".$this->wpdb_prefix."posts.ID = tt1.object_id251 INNER JOIN ".$this->wpdb_prefix."postmeta ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."postmeta.post_id252 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[] $productIds264 * @param int $limit265 * @param int $offset266 * @return \stdClass[] [productId, name]267 * @author Christian M. Jensen <christian@modified.dk>268 * @since 1.1.2269 */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."posts273 INNER JOIN ".$this->wpdb_prefix."term_relationships ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."term_relationships.object_id274 INNER JOIN ".$this->wpdb_prefix."term_relationships AS tt1 ON ".$this->wpdb_prefix."posts.ID = tt1.object_id275 INNER JOIN ".$this->wpdb_prefix."postmeta ON ".$this->wpdb_prefix."posts.ID = ".$this->wpdb_prefix."postmeta.post_id276 WHERE (277 ".$this->wpdb_prefix."term_relationships.term_taxonomy_id IN (278 SELECT t.term_id FROM ".$this->wpdb_prefix."terms AS t279 INNER JOIN ".$this->wpdb_prefix."term_taxonomy AS tt ON tt.term_id = t.term_id280 INNER JOIN ".$this->wpdb_prefix."term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id281 WHERE tt.taxonomy IN ('product_cat') AND tr.object_id IN282 (".implode(',', array_map('intval', $productIds)).") ORDER BY t.term_id ASC283 ) OR tt1.term_taxonomy_id IN (284 SELECT t.term_id FROM ".$this->wpdb_prefix."terms AS t285 INNER JOIN ".$this->wpdb_prefix."term_taxonomy AS tt ON tt.term_id = t.term_id286 INNER JOIN ".$this->wpdb_prefix."term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id287 WHERE tt.taxonomy IN ('product_tag') AND tr.object_id IN288 (".implode(',', array_map('intval', $productIds)).") ORDER BY t.term_id ASC289 )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[] $productIds303 * @return \stdClass[] [term_id, name]304 * @author Christian M. Jensen <christian@modified.dk>305 * @since 1.1.2306 */307 protected function getProductCategories(array $productIds)308 {309 $query = "SELECT t.*, tt.* FROM ".$this->wpdb_prefix."terms AS t310 INNER JOIN ".$this->wpdb_prefix."term_taxonomy AS tt ON tt.term_id = t.term_id311 INNER JOIN ".$this->wpdb_prefix."term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id312 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[] $productIds320 * @return \stdClass[] [term_id, name]321 * @author Christian M. Jensen <christian@modified.dk>322 * @since 1.1.2323 */324 protected function getProductTags(array $productIds)325 {326 $query = "SELECT t.term_id, t.name FROM ".$this->wpdb_prefix."terms AS t327 INNER JOIN ".$this->wpdb_prefix."term_taxonomy AS tt ON tt.term_id = t.term_id INNER328 JOIN ".$this->wpdb_prefix."term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id329 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();332 108 } 333 109 … … 503 279 504 280 /** 505 * get images meta data [post_id, file, meta, image_alt]506 * @param int[] $imagesIds507 * @return \stdClass[]508 * @author Christian M. Jensen <christian@modified.dk>509 * @since 1.1.2510 */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_alt514 FROM ".$this->wpdb_prefix."postmeta AS t1515 INNER JOIN ".$this->wpdb_prefix."postmeta AS t2516 ON t2.post_id=t1.post_id517 AND t2.meta_key='_wp_attachment_metadata'518 LEFT JOIN ".$this->wpdb_prefix."posts AS t3519 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 /**527 281 * Get WooCommerce instance 528 282 * @global array $GLOBALS -
avecdo-for-woocommerce/trunk/views/activated.php
r3463216 r3484553 1 1 <?php 2 if (isset($mes ages) && count($mesages) > 0):3 foreach ($mes ages as $type => $mesage):4 avecdoEchoNotice(implode('<br>', $mes age), $type, true);2 if (isset($messages) && count($messages) > 0): 3 foreach ($messages as $type => $message): 4 avecdoEchoNotice(implode('<br>', $message), $type, true); 5 5 endforeach; 6 6 endif; 7 7 $nonce = wp_create_nonce('avecdo_activation_form'); 8 $isVersion1 = $versionSelected == 1;9 ?>10 11 <?php12 // end of multi currency13 14 8 ?> 15 9 <div class="avecdo-wrapper"> 16 10 <div class="avecdo-content"> 17 11 <div class="avecdo-spacer-l"></div> 18 <?php include 'version-selector.php' ?>19 12 <div class="avecdo-box-notop"> 20 <?php if ( $isVersion1 ||!$multiCurrencyEnabled) : ?>13 <?php if (!$multiCurrencyEnabled) : ?> 21 14 <div class="avecdo-align-left"> 22 15 <h2 class="avecdo-shop-connected"><?php echo __('Your shop is connected.', 'avecdo-for-woocommerce'); ?></h2> … … 27 20 </div> 28 21 29 <?php if ( $isVersion1 ||!$multiCurrencyEnabled) : ?>22 <?php if (!$multiCurrencyEnabled) : ?> 30 23 <div class="avecdo-inner-container"> 31 24 <form method="post" action="<?php echo admin_url('admin.php?page=avecdo&activation=true'); ?>"> -
avecdo-for-woocommerce/trunk/views/index.php
r3463216 r3484553 1 1 <div class="avecdo-wrapper"> 2 2 <?php 3 if (isset($mes ages) && count($mesages) > 0):4 foreach ($mes ages as $type => $mesage):5 avecdoEchoNotice(implode('<br>', $mes age), $type, true);3 if (isset($messages) && count($messages) > 0): 4 foreach ($messages as $type => $message): 5 avecdoEchoNotice(implode('<br>', $message), $type, true); 6 6 endforeach; 7 7 endif; … … 28 28 <div class="avecdo-content"> 29 29 <div class="activation-flow"></div> 30 <?php include 'version-selector.php' ?>31 30 <div class="avecdo-box-notop"> 32 31 <div class="avecdo-align-left"> … … 38 37 <div class="avecdo-spacer-s"></div> 39 38 <div> 40 <?php if ( $versionSelected == 1 ||!$multiCurrencyEnabled || empty($languages)): ?>39 <?php if (!$multiCurrencyEnabled || empty($languages)): ?> 41 40 <form method="post" action="<?php echo admin_url('admin.php?page=avecdo&activation=true'); ?>"> 42 41 <input type="hidden" name="avecdo_submit_activation" value="1" />
Note: See TracChangeset
for help on using the changeset viewer.