Jump to content

Export data pack to Prestashop to another tools website thanks to API/Webservice


Futamiya

Recommended Posts

Prestashop V : 1.7.7.4

Version du logiciel serveur : Apache/2.4.47 (Unix) 

Version de PHP : 7.3.28

Localhost : Xampp Server

 

Hello,

I tried to transfer data, to Prestashop to another website.

But, for pack product, it doesn't work.

I started to learn PHP and Prestashop concept. But I am lost. I hope that someone thought about it and have much more informations than me.
I tried to understand how the concept of webservice et http server work. 

Sincerelly

Futamiya

Link to comment
Share on other sites

So

 

I tried 2 methods :

First

In override/classe/Product.php

<?php
class Product extends ProductCore
{
public function setWsProductBundle($product_bundle)
{
 Pack::deleteItems($this->id);
 if (count($product_bundle) > 0) {
  $this->setDefaultAttribute(0);//reset cache_default_attribute
  foreach ($product_bundle as $item) {
if (!$item['id'] || !$item['quantity'])
 return false;
if (!Pack::addItem((int)$this->id, (int)$item['id'], (int)$item['quantity']))
 return false;
  }
 }
 return true;
}
}
?>

Didn't work. They have changed nothing.

 

Second :

in  override/classes/

<?php
class ProductMergeCore extends ObjectModel
{
    public $product_item;
    public static $definition = array(
        'table' => 'pack',
        'primary' => 'PRIMARY',
        'fields' => array(
            'product_item' => array('type' => self::TYPE_INT, 'required' => true),
        ),
    );
    protected $webserviceParameters = array();
}

and in override/classes/webservice/WebServiceRequest.php

class WebserviceRequest extends WebserviceRequestCore
{
    public static function getResources()
    {
        $resources = parent::getResources();

        $resources['webservicename'] = array('description' => 'Description of webservice', 'specific_management' => true, 'forbidden_method' => array('PUT', 'DELETE'));
        ksort($resources);

        $resources['pack'] = array('description' => 'Test pack', 'class' => 'Pack');
        ksort($resources);

        return $resources;
    }

}

But with this 2nd method, I have this result :

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <products>
        <product id="1" xlink:href="https://localhost/my_shop/api/products/1"/>
        <product id="2" xlink:href="https://localhost/my_shop/api/products/2"/>
        <product id="3" xlink:href="https://localhost/my_shop/api/products/3"/>
        <product id="4" xlink:href="https://localhost/my_shop/api/products/4"/>
    </products>
</prestashop>

That return products, and all product. For example, 3, is not a item and is not pack. So I didn't know what the problem.

 

Sincerelly

Futamiya

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...