mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge pull request #1478 from woocommerce/PCP-895-buttons-not-working-on-single-product-page-for-woo-commerce-bookings-product
Buttons not working on single product page for WooCommerce Bookings product (895)
This commit is contained in:
commit
9d906a1f4b
8 changed files with 374 additions and 95 deletions
|
@ -73,6 +73,13 @@ class Item {
|
|||
*/
|
||||
protected $tax_rate;
|
||||
|
||||
/**
|
||||
* The cart item key.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $cart_item_key;
|
||||
|
||||
/**
|
||||
* Item constructor.
|
||||
*
|
||||
|
@ -84,6 +91,7 @@ class Item {
|
|||
* @param string $sku The SKU.
|
||||
* @param string $category The category.
|
||||
* @param float $tax_rate The tax rate.
|
||||
* @param ?string $cart_item_key The cart key for this item.
|
||||
*/
|
||||
public function __construct(
|
||||
string $name,
|
||||
|
@ -93,18 +101,20 @@ class Item {
|
|||
Money $tax = null,
|
||||
string $sku = '',
|
||||
string $category = 'PHYSICAL_GOODS',
|
||||
float $tax_rate = 0
|
||||
float $tax_rate = 0,
|
||||
string $cart_item_key = null
|
||||
) {
|
||||
|
||||
$this->name = $name;
|
||||
$this->unit_amount = $unit_amount;
|
||||
$this->quantity = $quantity;
|
||||
$this->description = $description;
|
||||
$this->tax = $tax;
|
||||
$this->sku = $sku;
|
||||
$this->category = ( self::DIGITAL_GOODS === $category ) ? self::DIGITAL_GOODS : self::PHYSICAL_GOODS;
|
||||
$this->category = $category;
|
||||
$this->tax_rate = $tax_rate;
|
||||
$this->name = $name;
|
||||
$this->unit_amount = $unit_amount;
|
||||
$this->quantity = $quantity;
|
||||
$this->description = $description;
|
||||
$this->tax = $tax;
|
||||
$this->sku = $sku;
|
||||
$this->category = ( self::DIGITAL_GOODS === $category ) ? self::DIGITAL_GOODS : self::PHYSICAL_GOODS;
|
||||
$this->category = $category;
|
||||
$this->tax_rate = $tax_rate;
|
||||
$this->cart_item_key = $cart_item_key;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,6 +189,15 @@ class Item {
|
|||
return round( (float) $this->tax_rate, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cart key for this item.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function cart_item_key():?string {
|
||||
return $this->cart_item_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object as array.
|
||||
*
|
||||
|
@ -202,6 +221,10 @@ class Item {
|
|||
$item['tax_rate'] = (string) $this->tax_rate();
|
||||
}
|
||||
|
||||
if ( $this->cart_item_key() ) {
|
||||
$item['cart_item_key'] = (string) $this->cart_item_key();
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,8 @@ class ItemFactory {
|
|||
public function from_wc_cart( \WC_Cart $cart ): array {
|
||||
$items = array_map(
|
||||
function ( array $item ): Item {
|
||||
$product = $item['data'];
|
||||
$product = $item['data'];
|
||||
$cart_item_key = $item['key'] ?? null;
|
||||
|
||||
/**
|
||||
* The WooCommerce product.
|
||||
|
@ -61,7 +62,9 @@ class ItemFactory {
|
|||
$this->prepare_description( $product->get_description() ),
|
||||
null,
|
||||
$product->get_sku(),
|
||||
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
|
||||
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
||||
0,
|
||||
$cart_item_key
|
||||
);
|
||||
},
|
||||
$cart->get_cart_contents()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue