Jump to content

Update image legend and position with web service


Obexto

Recommended Posts

  • 9 months later...
  • 5 years later...

Hi 

 

I add to modify classes/webservice/WebserviceSpecificManagementImages.php file to make it accept legend in post

in writePostedImageOnDisk method 

 

after 

elseif ($this->wsObject->method == 'POST') {
            if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) {
                $file = $_FILES['image'];
                if ($file['size'] > $this->imgMaxUploadSize) {
                    throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', ($this->imgMaxUploadSize / 1000)), array(72, 400));
                }
                require_once(_PS_CORE_DIR_.'/images.inc.php');
                if ($error = ImageManager::validateUpload($file)) {
                    throw new WebserviceException('Image upload error : '.$error, array(76, 400));
                }

                if (isset($file['tmp_name']) && $file['tmp_name'] != null) {
                    if ($this->imageType == 'products') {
                        $product = new Product((int)$this->wsObject->urlSegment[2]);
                        if (!Validate::isLoadedObject($product)) {
                            throw new WebserviceException('Product '.(int)$this->wsObject->urlSegment[2].' does not exist', array(76, 400));
                        }
                        $image = new Image();
                        $image->id_product = (int)($product->id);
                        $image->position = Image::getHighestPosition($product->id) + 1;

                        if (!Image::getCover((int)$product->id)) {
                            $image->cover = 1;
                        } else {
                            $image->cover = 0;
                        }

              
                       

 

add 

 

 $image->legend = $_POST["legend"];

 

and then you can add legend with uploaded picture 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...