Skip to content

Commit

Permalink
packaged version 4.35.0 (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
MlKilderkin committed Oct 13, 2022
1 parent 0b594d6 commit 386a4a2
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 36 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [4.35.0]

### Added
- Added subtotal and taxes display on AMP cart template
- Added ability to change quantity on AMP cart template
- Display product options(if applicable) on AMP cart template

### Changed
- Changed customer cache flush logic. Prevent situations when customer group rules don't apply after they have been changed in Bigcommerce Control Panel. To flush customers data go to plugin settings: Bigcommerce → Settings → Diagnostics → Flush users cache

## [4.34.0]

### Added
Expand Down Expand Up @@ -1831,6 +1841,7 @@
in fact, reset postdata, so far as Gutenberg 3.2.0 is concerned.


[4.35.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.34.0...4.35.0
[4.34.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.33.0...4.34.0
[4.33.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.32.0...4.33.0
[4.32.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.31.0...4.32.0
Expand Down
2 changes: 1 addition & 1 deletion bigcommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: BigCommerce for WordPress
Description: Scale your ecommerce business with WordPress on the front-end and BigCommerce on the back end. Free up server resources from things like catalog management, processing payments, and managing fulfillment logistics.
Author: BigCommerce
Version: 4.34.0
Version: 4.35.0
Author URI: https://www.bigcommerce.com/wordpress
Requires PHP: 7.4.0
Text Domain: bigcommerce
Expand Down
2 changes: 1 addition & 1 deletion build-timestamp.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '3.00.09.12.2022');
define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '3.47.10.10.2022');
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: bigcommerce, moderntribe, jbrinley, becomevocal, vincentlistrani,
Tags: ecommerce, online store, sell online, storefront, retail, online shop, bigcommerce, big commerce, e-commerce, physical products, buy buttons, commerce, shopping cart, checkout, cart, shop, headless commerce, shipping, payments, fulfillment
Requires at least: 5.2
Tested up to: 5.9.2
Stable tag: 4.34.0
Stable tag: 4.35.0
Requires PHP: 7.4.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
2 changes: 1 addition & 1 deletion src/BigCommerce/Accounts/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function set_customer_id( $customer_id ) {
* @return int|null
*/
public function get_group_id() {
$customer_id = is_user_logged_in() ? get_user_option( self::CUSTOMER_ID_META, $this->wp_user_id ) : 0;
$customer_id = is_user_logged_in() || defined( 'DOING_CRON' ) ? get_user_option( self::CUSTOMER_ID_META, $this->wp_user_id ) : 0;
if ( ! $customer_id ) {
/**
* This filter is documented in src/BigCommerce/Accounts/Customer.php
Expand Down
5 changes: 4 additions & 1 deletion src/BigCommerce/Import/Processors/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ private function clean_tasks( $pre_import = false ) {
public function clean_customer_group_transients(): void {
$users_ids = get_users( [ 'fields' => 'ID' ] );
foreach ( $users_ids as $users_id ) {
$customer_id = get_user_option( Customer::CUSTOMER_ID_META, $users_id );
$customer_id = get_user_option( Customer::CUSTOMER_ID_META, $users_id );
$customer = new Customer( $users_id );
delete_transient( sprintf( 'bccustgroupinfo%d', $customer->get_group_id() ) );
$transient_key = sprintf( 'bccustomergroup%d', $customer_id );
delete_transient( $transient_key );
delete_transient( sprintf( 'bccustomervisibleterms%d', $users_id ) );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/BigCommerce/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace BigCommerce;

class Plugin {
const VERSION = '4.34.0';
const VERSION = '4.35.0';

protected static $_instance;

Expand Down
89 changes: 88 additions & 1 deletion src/BigCommerce/Proxy/AMP_Cart_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,17 @@ public function get_items( $request ) {
return rest_ensure_response( null );
}

$query_params = [
'include' => [
'line_items.physical_items.options',
'line_items.digital_items.options',
'redirect_urls',
],
];

$request = new WP_REST_Request(
'GET',
sprintf( '/%scarts/%s', trailingslashit( $this->proxy_base ), $cart_id )
sprintf( '/%scarts/%s?%s', trailingslashit( $this->proxy_base ), $cart_id, http_build_query( $query_params ) ),
);

$response = rest_do_request( $request );
Expand All @@ -136,6 +144,85 @@ public function get_items( $request ) {
$data['cart_amount']
);

$data = $this->get_cart_totals( $data );

return rest_ensure_response( $data );
}

protected function get_cart_totals( $data ) {
$cart = [
'base_amount' => [
'raw' => $data['base_amount'],
'formatted' => $this->get_formatted_price( $data['base_amount'] ),
],
'discount_amount' => [
'raw' => $data['discount_amount'],
'formatted' => $this->get_formatted_price( $data['discount_amount'] ),
],
'cart_amount' => [
'raw' => $data['cart_amount'],
'formatted' => $this->get_formatted_price( $data['cart_amount'] ),
],
'tax_included' => (bool) $data['tax_included'],
'coupons' => $data['coupons'],
];

$coupons_discount_amount = $this->get_coupons_discount_amount( $data['coupons'] );

$cart[ 'coupons_discount_amount' ] = [
'raw' => $coupons_discount_amount,
'formatted' => $this->get_formatted_price( $coupons_discount_amount ),
];

$tax_amount = $this->calculate_total_tax(
$cart[ 'cart_amount' ][ 'raw' ],
$cart[ 'discount_amount' ][ 'raw' ],
$coupons_discount_amount,
$data[ 'items' ]
);

$cart[ 'tax_amount' ] = [
'raw' => $tax_amount,
'formatted' => $this->get_formatted_price( $tax_amount ),
];

if ( $data[ 'tax_included' ] || $tax_amount < 0 ) {
$subtotal = $cart[ 'cart_amount' ][ 'raw' ];
} else {
$subtotal = $cart[ 'cart_amount' ][ 'raw' ] - $tax_amount;
}

$cart[ 'subtotal' ] = [
'raw' => $subtotal,
'formatted' => $this->get_formatted_price( $subtotal ),
];

return array_merge( $data, $cart );
}

private function get_formatted_price( $value ) {
return apply_filters( 'bigcommerce/currency/format', sprintf( '¤%0.2f', $value ), $value );
}

/**
* @param float $cart_amount The `cart_amount` value for the cart
* @param float $discount_amount The `discount_amount` value for the cart
* @param float $coupons_discount_amount The `coupons_discount_amount` value for the cart
* @param array $items The items in the cart
*
* @return float
*/
private function calculate_total_tax( $cart_amount, $discount_amount, $coupons_discount_amount, $items ) {
$item_sum = array_sum( array_map( function ( $item ) {
return isset( $item[ 'sale_price' ] ) ? $item[ 'sale_price' ] * $item['quantity'] : 0;
}, $items ) );

return $cart_amount + $discount_amount + $coupons_discount_amount - $item_sum;
}

private function get_coupons_discount_amount( array $coupons ) {
return array_reduce( $coupons, function( $carry, $coupon ) {
return $carry + $coupon['discounted_amount'];
}, 0 );
}
}
3 changes: 1 addition & 2 deletions templates/public/amp/archive-bigcommerce_product.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
* Default Product Archive Template
* Override this template in your own theme by creating a file at
* [your-theme]/bigcommerce/archive-bigcommerce_product.php
*
*
* @version 1.0.0
*/

if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}

amp_add_post_template_actions();
$post = get_post();
$amp_post_template = new AMP_Post_Template( $post );

Expand Down
32 changes: 30 additions & 2 deletions templates/public/amp/components/cart/cart-items.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class="bc-cart-body"
method="post"
on="submit:AMP.setState({savingItem: true});submit-success:product-list.refresh,subtotal.refresh,AMP.setState({savingItem: false})"
>
<input type="hidden" name="cartId" value="CLIENT_ID(bigcommerce_cart_id)" data-amp-replace="CLIENT_ID" />
<input type="hidden" name="cartId" value="CLIENT_ID(<?php echo Cart::CART_COOKIE; ?>)" data-amp-replace="CLIENT_ID" />
<button
class="bc-link bc-cart-item__remove-button"
type="submit"
Expand All @@ -70,10 +70,38 @@ class="bc-link bc-cart-item__remove-button"
{{ #brand }}
<span class="bc-cart-item__product-brand">{{ brand }}</span>
{{ /brand }}

{{ #options }}
<div class="bc-cart-item__product-options">
<span class="bc-cart-item__product-option">
<span class="bc-cart-item__product-option-label">{{ name }}</span>
<span class="bc-cart-item__product-option-value">{{ value }}</span>
</span>
</div>
{{ /options }}
</div>

<div class="bc-cart-item-quantity">
{{ quantity }}
<form
id="item-{{ id }}-quantity"
action-xhr="<?php echo esc_url( rest_url( sprintf( '/%s/carts/_cart_id_/items/', $proxy_base ) ) ); ?>{{ id }}?qty=true'"
on="submit:AMP.setState({savingItem: true});submit-success:product-list.refresh,subtotal.refresh,AMP.setState({savingItem: false})"
method="post"
>
<input type="hidden" name="product_id" value="{{ product_id }}" />
<input type="hidden" name="variant_id" value="{{ variant_id }}" />
<input type="hidden" name="cartId" value="CLIENT_ID(<?php echo Cart::CART_COOKIE; ?>)" data-amp-replace="CLIENT_ID" />
<input
type="number"

name="quantity"
class="bc-cart-item__quantity-input"
data-js="bc-cart-item__quantity"
value="{{ quantity }}"
on="change:item-{{ id }}-quantity.submit"
min="1"
/>
</form>
</div>

<div class="bc-cart-item-total-price">
Expand Down
25 changes: 23 additions & 2 deletions templates/public/amp/components/cart/cart-summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,28 @@ class="bc-cart-subtotal"
reset-on-refresh
>
<template type="amp-mustache">
<span class="bc-cart-subtotal__label"><?php esc_html_e( 'Subtotal: ', 'bigcommerce' ); ?></span>
<span class="bc-cart-subtotal__amount">{{ total }}</span>
<div class="bc-cart-subtotal">
<span class="bc-cart-subtotal__label"><?php esc_html_e( 'Subtotal: ', 'bigcommerce' ); ?></span>
<span class="bc-cart-subtotal__amount">{{ subtotal.formatted }}</span>
</div>
{{ #tax_amount }}
<div class="bc-cart-tax">
<span class="bc-cart-tax__label">
{{ #tax_included }}
<?php echo __( 'Estimated Tax Included in Subtotal: ', 'bigcommerce' ); ?>
{{ /tax_included }}
{{ ^tax_included }}
<?php echo __( 'Estimated Taxes: ', 'bigcommerce' ); ?>
{{ /tax_included }}
</span>
<span class="bc-cart-tax__amount">
{{ tax_amount.formatted }}
</span>
</div>
{{ /tax_amount }}
<div class="bc-cart-total">
<span class="bc-cart-total__label"><?php echo esc_html( __( 'Cart Total: ', 'bigcommerce' ) ); ?></span>
<span class="bc-cart-total__amount">{{ total }}</span>
</div>
</template>
</amp-list>
1 change: 0 additions & 1 deletion templates/public/amp/components/products/product-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

<form action-xhr="<?php echo esc_url( trailingslashit( $product->purchase_url() ) ); ?>" method="post" enctype="multipart/form-data" class="bc-form bc-product-form" target="_top">
<?php echo $options; // WPCS: XSS ok. Already escaped data. ?>
<?php echo $modifiers; // WPCS: XSS ok. Already escaped data. ?>
<div class="bc-product-form__product-message" data-js="bc-product-message"></div>
<input type="hidden" name="variant_id" class="variant_id" [value]="<?php echo esc_attr( $variant_id_expression ); ?>">
<div class="bc-product-form__quantity">
Expand Down
10 changes: 1 addition & 9 deletions templates/public/amp/components/products/product-single.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,7 @@
<?php echo $brand; // WPCS: XSS ok. Already escaped data. ?>
<?php echo $price; // WPCS: XSS ok. Already escaped data. ?>
<?php echo $rating; // WPCS: XSS ok. Already escaped data. ?>

<?php if ( $sku ) { ?>
<span class="bc-product__sku">
<span class="bc-product-single__meta-label">
<?php esc_html_e( 'SKU:', 'bigcommerce' ); ?>
</span>
<?php echo esc_html( $sku ); ?>
</span>
<?php } ?>
<?php echo $sku; ?>
<?php echo $form; // WPCS: XSS ok. Already escaped data. ?>
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit7f327a3a3b1eac49a00726c87c0fc0d4::getLoader();
return ComposerAutoloaderInitbc47ae46b55b55c82ca9433553970f53::getLoader();
14 changes: 7 additions & 7 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit7f327a3a3b1eac49a00726c87c0fc0d4
class ComposerAutoloaderInitbc47ae46b55b55c82ca9433553970f53
{
private static $loader;

Expand All @@ -19,15 +19,15 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit7f327a3a3b1eac49a00726c87c0fc0d4', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitbc47ae46b55b55c82ca9433553970f53', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit7f327a3a3b1eac49a00726c87c0fc0d4', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitbc47ae46b55b55c82ca9433553970f53', 'loadClassLoader'));

$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';

call_user_func(\Composer\Autoload\ComposerStaticInit7f327a3a3b1eac49a00726c87c0fc0d4::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
Expand All @@ -39,19 +39,19 @@ public static function getLoader()
$loader->register(true);

if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit7f327a3a3b1eac49a00726c87c0fc0d4::$files;
$includeFiles = Composer\Autoload\ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire7f327a3a3b1eac49a00726c87c0fc0d4($fileIdentifier, $file);
composerRequirebc47ae46b55b55c82ca9433553970f53($fileIdentifier, $file);
}

return $loader;
}
}

function composerRequire7f327a3a3b1eac49a00726c87c0fc0d4($fileIdentifier, $file)
function composerRequirebc47ae46b55b55c82ca9433553970f53($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;
Expand Down
10 changes: 5 additions & 5 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit7f327a3a3b1eac49a00726c87c0fc0d4
class ComposerStaticInitbc47ae46b55b55c82ca9433553970f53
{
public static $files = array (
'5255c38a0faeba867671b61dfda6d864' => __DIR__ . '/..' . '/paragonie/random_compat/lib/random.php',
Expand Down Expand Up @@ -1163,10 +1163,10 @@ class ComposerStaticInit7f327a3a3b1eac49a00726c87c0fc0d4
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit7f327a3a3b1eac49a00726c87c0fc0d4::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit7f327a3a3b1eac49a00726c87c0fc0d4::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticInit7f327a3a3b1eac49a00726c87c0fc0d4::$prefixesPsr0;
$loader->classMap = ComposerStaticInit7f327a3a3b1eac49a00726c87c0fc0d4::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::$prefixesPsr0;
$loader->classMap = ComposerStaticInitbc47ae46b55b55c82ca9433553970f53::$classMap;

}, null, ClassLoader::class);
}
Expand Down

0 comments on commit 386a4a2

Please sign in to comment.