mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Product Title: Ensure the product title in addition to the product description gets correctly sanitized and trimmed before getting sent to PayPal
This commit is contained in:
parent
0ce740ba62
commit
27b8155766
4 changed files with 13 additions and 13 deletions
|
@ -61,10 +61,10 @@ class ItemFactory {
|
||||||
|
|
||||||
$price = (float) $item['line_subtotal'] / (float) $item['quantity'];
|
$price = (float) $item['line_subtotal'] / (float) $item['quantity'];
|
||||||
return new Item(
|
return new Item(
|
||||||
mb_substr( $product->get_name(), 0, 127 ),
|
$this->prepare_item_string( $product->get_name() ),
|
||||||
new Money( $price, $this->currency ),
|
new Money( $price, $this->currency ),
|
||||||
$quantity,
|
$quantity,
|
||||||
$this->prepare_description( $product->get_description() ),
|
$this->prepare_item_string( $product->get_description() ),
|
||||||
null,
|
null,
|
||||||
$this->prepare_sku( $product->get_sku() ),
|
$this->prepare_sku( $product->get_sku() ),
|
||||||
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
||||||
|
@ -138,10 +138,10 @@ class ItemFactory {
|
||||||
$image = $product instanceof WC_Product ? wp_get_attachment_image_src( (int) $product->get_image_id(), 'full' ) : '';
|
$image = $product instanceof WC_Product ? wp_get_attachment_image_src( (int) $product->get_image_id(), 'full' ) : '';
|
||||||
|
|
||||||
return new Item(
|
return new Item(
|
||||||
mb_substr( $item->get_name(), 0, 127 ),
|
$this->prepare_item_string( $item->get_name() ),
|
||||||
new Money( $price_without_tax_rounded, $currency ),
|
new Money( $price_without_tax_rounded, $currency ),
|
||||||
$quantity,
|
$quantity,
|
||||||
$product instanceof WC_Product ? $this->prepare_description( $product->get_description() ) : '',
|
$product instanceof WC_Product ? $this->prepare_item_string( $product->get_description() ) : '',
|
||||||
null,
|
null,
|
||||||
$product instanceof WC_Product ? $this->prepare_sku( $product->get_sku() ) : '',
|
$product instanceof WC_Product ? $this->prepare_sku( $product->get_sku() ) : '',
|
||||||
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
||||||
|
@ -160,7 +160,7 @@ class ItemFactory {
|
||||||
*/
|
*/
|
||||||
private function from_wc_order_fee( \WC_Order_Item_Fee $item, \WC_Order $order ): Item {
|
private function from_wc_order_fee( \WC_Order_Item_Fee $item, \WC_Order $order ): Item {
|
||||||
return new Item(
|
return new Item(
|
||||||
$item->get_name(),
|
$this->prepare_item_string( $item->get_name() ),
|
||||||
new Money( (float) $item->get_amount(), $order->get_currency() ),
|
new Money( (float) $item->get_amount(), $order->get_currency() ),
|
||||||
$item->get_quantity(),
|
$item->get_quantity(),
|
||||||
'',
|
'',
|
||||||
|
|
|
@ -12,14 +12,14 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Helper;
|
||||||
trait ItemTrait {
|
trait ItemTrait {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanups the description and prepares it for sending to PayPal.
|
* Cleans up item strings (title and description for example) and prepares them for sending to PayPal.
|
||||||
*
|
*
|
||||||
* @param string $description Item description.
|
* @param string $description Item description.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function prepare_description( string $description ): string {
|
protected function prepare_item_string( string $string ): string {
|
||||||
$description = strip_shortcodes( wp_strip_all_tags( $description ) );
|
$string = strip_shortcodes( wp_strip_all_tags( $string ) );
|
||||||
return substr( $description, 0, 127 ) ?: '';
|
return substr( $string, 0, 127 ) ?: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -169,10 +169,10 @@ class Shipment implements ShipmentInterface {
|
||||||
$image = wp_get_attachment_image_src( (int) $product->get_image_id(), 'full' );
|
$image = wp_get_attachment_image_src( (int) $product->get_image_id(), 'full' );
|
||||||
|
|
||||||
$ppcp_order_item = new Item(
|
$ppcp_order_item = new Item(
|
||||||
mb_substr( $item->get_name(), 0, 127 ),
|
$this->prepare_item_string( $item->get_name() ),
|
||||||
new Money( $price_without_tax_rounded, $currency ),
|
new Money( $price_without_tax_rounded, $currency ),
|
||||||
$quantity,
|
$quantity,
|
||||||
$this->prepare_description( $product->get_description() ),
|
$this->prepare_item_string( $product->get_description() ),
|
||||||
null,
|
null,
|
||||||
$this->prepare_sku( $product->get_sku() ),
|
$this->prepare_sku( $product->get_sku() ),
|
||||||
$product->is_virtual() ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
$product->is_virtual() ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
||||||
|
|
|
@ -114,7 +114,7 @@ class SubscriptionsApiHandler {
|
||||||
*/
|
*/
|
||||||
public function create_product( WC_Product $product ) {
|
public function create_product( WC_Product $product ) {
|
||||||
try {
|
try {
|
||||||
$subscription_product = $this->products_endpoint->create( $product->get_title(), $this->prepare_description( $product->get_description() ) );
|
$subscription_product = $this->products_endpoint->create( $this->prepare_item_string( $product->get_title() ), $this->prepare_item_string( $product->get_description() ) );
|
||||||
$product->update_meta_data( 'ppcp_subscription_product', $subscription_product->to_array() );
|
$product->update_meta_data( 'ppcp_subscription_product', $subscription_product->to_array() );
|
||||||
$product->save();
|
$product->save();
|
||||||
} catch ( RuntimeException $exception ) {
|
} catch ( RuntimeException $exception ) {
|
||||||
|
@ -169,7 +169,7 @@ class SubscriptionsApiHandler {
|
||||||
$catalog_product_name = $catalog_product->name() ?: '';
|
$catalog_product_name = $catalog_product->name() ?: '';
|
||||||
$catalog_product_description = $catalog_product->description() ?: '';
|
$catalog_product_description = $catalog_product->description() ?: '';
|
||||||
|
|
||||||
$wc_product_description = $this->prepare_description( $product->get_description() ) ?: $product->get_title();
|
$wc_product_description = $this->prepare_item_string( $product->get_description() ) ?: $this->prepare_item_string( $product->get_title() );
|
||||||
|
|
||||||
if ( $catalog_product_name !== $product->get_title() || $catalog_product_description !== $wc_product_description ) {
|
if ( $catalog_product_name !== $product->get_title() || $catalog_product_description !== $wc_product_description ) {
|
||||||
$data = array();
|
$data = array();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue