mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
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:
commit
5ca0e16b5b
4 changed files with 35 additions and 18 deletions
|
@ -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(
|
||||
|
|
|
@ -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 ) ?: '';
|
||||
}
|
||||
}
|
||||
|
|
24
modules/ppcp-api-client/src/Helper/ItemTrait.php
Normal file
24
modules/ppcp-api-client/src/Helper/ItemTrait.php
Normal 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 ) ?: '';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue