Merge pull request #1700 from woocommerce/PCP-1797-critical-error-when-editing-the-description-of-a-product-linked-with-a-pay-pal-subscription-to-exceed-127-characters

Error when product description linked with a PayPal subscription exceeds 127 characters (1797)
This commit is contained in:
Emili Castells 2023-09-19 14:29:25 +02:00 committed by GitHub
commit 5ca0e16b5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 18 deletions

View file

@ -83,13 +83,10 @@ class CatalogProducts {
*/
public function create( string $name, string $description ): Product {
$data = array(
'name' => $name,
'name' => $name,
'description' => $description ?: $name,
);
if ( $description ) {
$data['description'] = $description;
}
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v1/catalogs/products';
$args = array(

View file

@ -13,11 +13,15 @@ use WC_Product;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Helper\ItemTrait;
/**
* Class ItemFactory
*/
class ItemFactory {
use ItemTrait;
/**
* 3-letter currency code of the shop.
*
@ -211,15 +215,4 @@ class ItemFactory {
$image_url
);
}
/**
* Cleanups the description and prepares it for sending to PayPal.
*
* @param string $description Item description.
* @return string
*/
protected function prepare_description( string $description ): string {
$description = strip_shortcodes( wp_strip_all_tags( $description ) );
return substr( $description, 0, 127 ) ?: '';
}
}

View file

@ -0,0 +1,24 @@
<?php
/**
* PayPal item helper.
*
* @package WooCommerce\PayPalCommerce\ApiClient\Helper
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Helper;
trait ItemTrait {
/**
* Cleanups the description and prepares it for sending to PayPal.
*
* @param string $description Item description.
* @return string
*/
protected function prepare_description( string $description ): string {
$description = strip_shortcodes( wp_strip_all_tags( $description ) );
return substr( $description, 0, 127 ) ?: '';
}
}