Skip to content

Commit

Permalink
Merge pull request #292 from Ecwid/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
meteor-ec authored Aug 5, 2024
2 parents 0a9aace + 4a26e5e commit 17cf9bf
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
== Changelog ==
= 6.12.17 - Aug 5, 2024 =
- Internal improvements and optimizations.

= 6.12.16 - Jul 16, 2024 =
- Resolved an issue with the store sometimes failing to connect to a plugin.
- Additionally, we've fixed a problem that in some cases caused direct category links to display a 404 Not Found page.
Expand Down
2 changes: 1 addition & 1 deletion ecwid-shopping-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Description: Ecwid by Lightspeed is a free full-featured shopping cart. It can be easily integrated with any Wordpress blog and takes less than 5 minutes to set up.
Text Domain: ecwid-shopping-cart
Author: Ecwid Ecommerce
Version: 6.12.16
Version: 6.12.17
Author URI: https://ecwid.to/ecwid-site
License: GPLv2 or later
*/
Expand Down
40 changes: 31 additions & 9 deletions js/static-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
var invisibleDynamicContainerStyle = "display: block !important; height: 0 !important; max-height: 0 !important; min-height: 0 !important; overflow-y: auto !important; margin: 0 !important; padding: 0 !important;";
var mainCategoryId = 0;
var initialCategoryOffset = 0;
var pageAlreadyLoaded = false;

function find(selector) {
return document.querySelector(selector);
Expand Down Expand Up @@ -228,7 +229,9 @@
// if we've already switched to dynamic, we don't need to dispatch this event anymore
return;
}
var storeClosed = window.ecwid_initial_data.data.storeClosed;
var storeClosed = window.ecwid_initial_data !== undefined
? window.ecwid_initial_data.data.storeClosed // Storefront v2
: false; // Storefront v3
var storeClosedWrapper = document.querySelectorAll('.ecwid-maintenance-wrapper');
var storeNotClosedAndWrapperExists = !storeClosed && storeClosedWrapper.length > 0;

Expand Down Expand Up @@ -269,7 +272,8 @@
return;
}

if (!ecwidPageOpened
if (!hasEcwidMessages()
&& !ecwidPageOpened
&& openedPage.type === "CATEGORY"
&& openedPage.categoryId === mainCategoryId
&& openedPage.offset === initialCategoryOffset) {
Expand Down Expand Up @@ -359,8 +363,8 @@
}
}

addClickHandlers('#' + staticId + ' .ec-breadcrumbs a', function (element) {
var categoryId = element.getAttribute('categoryId');
addClickHandlers('#' + staticId + ' .breadcrumbs__link', function (element) {
var categoryId = element.getAttribute('data-category-id');
if (categoryId !== mainCategoryId) {
addStaticClickEvent(element, openEcwidPage('category', { 'id': categoryId }));
}
Expand Down Expand Up @@ -408,9 +412,15 @@
addStaticClickEvent(element, openEcwidPage('category', { 'id': categoryId }));
})

addClickHandlers('#' + staticId + ' .grid-product__buy-now', function (element) {
var productId = element.getAttribute('data-product-id');
addStaticClickEvent(element, openEcwidPage('product', { 'id': productId }));
addClickHandlers('#' + staticId + ' .grid-product__buy-now .form-control', function (element) {
const productId = element.getAttribute('data-product-id');
const isGermanStore = element.getAttribute('data-country-code') === 'DE';
const updatedBuyButtonsFeature = element.getAttribute('data-updated-buy-buttons') != null;
const params = { 'id': productId };
if (updatedBuyButtonsFeature && !isGermanStore) {
params['buyNow'] = '';
}
addStaticClickEvent(element, openEcwidPage('product', params, true));
});

addClickHandlers('#' + staticId + ' .footer__link--gift-card', function (element) {
Expand Down Expand Up @@ -500,8 +510,11 @@
});
}

function openEcwidPage(page, params) {
function openEcwidPage(page, params, stopPropagation = false) {
return function (e) {
if (stopPropagation) {
e.stopPropagation();
}
if (isCtrlClickOnProductEvent(page, e)) {
// In case product element in grid was clicked with ctrl/meta key, do not invoke e.preventDefault()
// and do nothing. Event will be handled and processed by default ctrl/meta + click handler on
Expand Down Expand Up @@ -537,6 +550,12 @@
}

function addOnPageLoadedCallback(callback, attempt) {
const isModernStorefront = window.Ecwid && window.Ecwid.isStorefrontV3 && window.Ecwid.isStorefrontV3();
if (isModernStorefront && pageAlreadyLoaded) {
callback();
return;
}

// let's wait for the Ecwid environment to be loaded for up to 2000 milliseconds
if (attempt >= 40) {
if (!!console) {
Expand All @@ -546,7 +565,10 @@
}

if (typeof (Ecwid) == 'object' && typeof (Ecwid.OnPageLoaded) == 'object') {
Ecwid.OnPageLoaded.add(callback);
Ecwid.OnPageLoaded.add(function (page) {
pageAlreadyLoaded = true;
callback(page);
});
} else {
setTimeout(function () {
addOnPageLoadedCallback(callback, attempt + 1);
Expand Down
54 changes: 49 additions & 5 deletions lib/ecwid_api_v3.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public function get_categories( $input_params ) {
$result = EcwidPlatform::get_from_categories_cache( $url );

if ( ! $result ) {
if ( empty( $options ) ) {
return false;
}

$result = EcwidPlatform::fetch_url( $url, $options );

if ( $result['code'] != '200' ) {
Expand Down Expand Up @@ -262,6 +266,10 @@ public function get_category( $category_id ) {
$result = EcwidPlatform::get_from_categories_cache( $url );

if ( ! $result ) {
if ( empty( $options ) ) {
return false;
}

$result = EcwidPlatform::fetch_url( $url, $options );

if ( $result['code'] != '200' ) {
Expand Down Expand Up @@ -316,6 +324,10 @@ public function get_product( $product_id ) {
$result = EcwidPlatform::get_from_products_cache( $url );

if ( ! $result ) {
if ( empty( $options ) ) {
return false;
}

$result = EcwidPlatform::fetch_url( $url, $options );

if ( $result['code'] != '200' ) {
Expand Down Expand Up @@ -364,7 +376,12 @@ public function search_products( $input_params ) {
$result = EcwidPlatform::get_from_products_cache( $url );

if ( ! $result ) {
if ( empty( $options ) ) {
return false;
}

$result = EcwidPlatform::fetch_url( $url, $options );

if ( $result['code'] != '200' ) {
return false;
}
Expand Down Expand Up @@ -410,6 +427,10 @@ public function get_deleted_products( $input_params ) {
$params
);

if ( empty( $options ) ) {
return false;
}

$result = EcwidPlatform::fetch_url( $url, $options );

if ( $result['code'] != '200' ) {
Expand Down Expand Up @@ -444,6 +465,10 @@ public function get_products( $input_params ) {
$params
);

if ( empty( $options ) ) {
return false;
}

$result = EcwidPlatform::fetch_url( $url, $options );

if ( $result['code'] != '200' ) {
Expand Down Expand Up @@ -568,6 +593,10 @@ public function get_store_update_stats( $additional_params = false ) {
$options = $this->build_request_headers();
$url = $this->build_request_url( $url, $params );

if ( empty( $options ) ) {
return false;
}

$result = EcwidPlatform::fetch_url( $url, $options );

if ( ! isset( $result['data'] ) ) {
Expand Down Expand Up @@ -607,6 +636,10 @@ public function get_store_profile( $disable_cache = false ) {
$options = $this->build_request_headers();
$url = $this->build_request_url( $this->_profile_api_url, $params );

if ( empty( $options ) ) {
return false;
}

$result = EcwidPlatform::fetch_url( $url, $options );

if ( @$result['code'] == '403' ) {
Expand Down Expand Up @@ -821,11 +854,14 @@ protected function build_request_url( $url, $input_params ) {
}

protected function build_request_headers() {
$headers = array(
'headers' => array(
'Authorization' => 'Bearer ' . self::get_token(),
),
);
$headers = array();
$token = self::get_token();

if ( ! empty( $token ) ) {
$headers['headers'] = array(
'Authorization' => 'Bearer ' . $token,
);
}

return $headers;
}
Expand Down Expand Up @@ -988,6 +1024,10 @@ public function get_starter_site_info() {
$options = $this->build_request_headers();
$url = $this->build_request_url( $this->_starter_site_api_url, $request_params );

if ( empty( $options ) ) {
return false;
}

$result = EcwidPlatform::fetch_url( $url, $options );

if ( ! isset( $result['data'] ) ) {
Expand Down Expand Up @@ -1102,6 +1142,10 @@ public function get_batch_status( $ticket ) {
$options = $this->build_request_headers();
$url = $this->build_request_url( $this->_batch_requests_api_url, $params );

if ( empty( $options ) ) {
return false;
}

$result = EcwidPlatform::fetch_url( $url, $options );

if ( @$result['code'] != '200' ) {
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Requires at least: 4.4
Tested up to: 6.6
Stable tag: 6.12.16
Stable tag: 6.12.17

Powerful, easy to use ecommerce shopping cart for WordPress. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available.

Expand Down Expand Up @@ -153,6 +153,9 @@ You can use Ecwid’s built-in import tools to copy your store products from any
* [Ecwid Help Center](http://help.ecwid.com "Ecwid Help")

== Changelog ==
= 6.12.17 - Aug 5, 2024 =
- Internal improvements and optimizations.

= 6.12.16 - Jul 16, 2024 =
- Resolved an issue with the store sometimes failing to connect to a plugin.
- Additionally, we've fixed a problem that in some cases caused direct category links to display a 404 Not Found page.
Expand Down

0 comments on commit 17cf9bf

Please sign in to comment.