mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Merge pull request #2033 from woocommerce/PCP-2666-ensure-sku-is-trimmed-to-127-characters-max
Prepare the SKU for sending to PayPal (2666)
This commit is contained in:
commit
11f5544f90
3 changed files with 16 additions and 14 deletions
|
@ -66,7 +66,7 @@ class ItemFactory {
|
|||
$quantity,
|
||||
$this->prepare_description( $product->get_description() ),
|
||||
null,
|
||||
$product->get_sku(),
|
||||
$this->prepare_sku( $product->get_sku() ),
|
||||
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
||||
$product->get_permalink(),
|
||||
$image[0] ?? '',
|
||||
|
@ -143,7 +143,7 @@ class ItemFactory {
|
|||
$quantity,
|
||||
$product instanceof WC_Product ? $this->prepare_description( $product->get_description() ) : '',
|
||||
null,
|
||||
$product instanceof WC_Product ? $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->get_permalink() : '',
|
||||
$image[0] ?? ''
|
||||
|
|
|
@ -21,4 +21,14 @@ trait ItemTrait {
|
|||
$description = strip_shortcodes( wp_strip_all_tags( $description ) );
|
||||
return substr( $description, 0, 127 ) ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the sku for sending to PayPal.
|
||||
*
|
||||
* @param string $sku Item sku.
|
||||
* @return string
|
||||
*/
|
||||
protected function prepare_sku( string $sku ): string {
|
||||
return substr( wp_strip_all_tags( $sku ), 0, 127 ) ?: '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use WC_Order_Item_Product;
|
|||
use WC_Product;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\ItemTrait;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\OrderTrackingModule;
|
||||
|
||||
/**
|
||||
|
@ -21,6 +22,8 @@ use WooCommerce\PayPalCommerce\OrderTracking\OrderTrackingModule;
|
|||
*/
|
||||
class Shipment implements ShipmentInterface {
|
||||
|
||||
use ItemTrait;
|
||||
|
||||
/**
|
||||
* The WC order ID.
|
||||
*
|
||||
|
@ -171,7 +174,7 @@ class Shipment implements ShipmentInterface {
|
|||
$quantity,
|
||||
$this->prepare_description( $product->get_description() ),
|
||||
null,
|
||||
$product->get_sku(),
|
||||
$this->prepare_sku( $product->get_sku() ),
|
||||
$product->is_virtual() ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
||||
$product->get_permalink(),
|
||||
$image[0] ?? ''
|
||||
|
@ -239,17 +242,6 @@ class Shipment implements ShipmentInterface {
|
|||
return $shipment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ) ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the shipment line items info.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue