product = $product; $this->soft_delete = $is_soft_delete; } /** * Gets the object batch. * * @since 2.0.0 * * @param \Square\Models\CatalogObject|null $catalog_object existing catalog object or null to create a new one * @return \Square\Models\CatalogObjectBatch * @throws \Exception */ public function get_batch( \Square\Models\CatalogObject $catalog_object = null ) { if ( ! $this->batch ) { $this->create_batch( $catalog_object ); } return $this->batch; } /** * Gets the total number of objects in the batch. * * @since 2.0.0 * * @return int */ public function get_batch_object_count() { return $this->batch_object_count; } /** * Returns whether this catalog object should be soft-deleted. * * @since 2.0.0 * * @return bool */ protected function is_soft_delete() { return true === $this->soft_delete; } /** * Creates a batch containing this item and any variations. * * @since 2.0.0 * * @param \Square\Models\CatalogObject|null $catalog_object existing catalog object or null to create a new one * @throws \Exception */ protected function create_batch( \Square\Models\CatalogObject $catalog_object = null ) { if ( ! $catalog_object ) { $catalog_id = Product\Woo_SOR::get_square_item_id( $this->product ); $catalog_object = new \Square\Models\CatalogObject( 'ITEM', '' ); } // update the object data from the Woo product $catalog_object = Product\Woo_SOR::update_catalog_item( $catalog_object, $this->product ); $batch_data = array( $catalog_object ); $this->batch = new \Square\Models\CatalogObjectBatch( $batch_data ); $variations = $catalog_object->getItemData()->getVariations() ?: array(); $this->batch_object_count = 1 + count( $variations ); } }