Giter VIP home page Giter VIP logo

Comments (7)

vienthuong avatar vienthuong commented on July 19, 2024 1

Hi @solverat
I got your intention here, if the payload is relatively small I'd just put it into the payload

$productRepository->create([
    'active' => true, // or $product->active
], $context); 

Or

$productRepository->create(array_filter($product->jsonSerialize()), $context); 

Will it work in your case? Filtering every null property out seems not a correct approach. For example when you want to set a property back to null then you need to define that property as null.

But feel free to create a PR or just a draft solution then I will take a look if it could be a good idea to add the method, thanks

from shopware-php-sdk.

jakub-groncki avatar jakub-groncki commented on July 19, 2024 1

Hi @vienthuong,

I was thinking about the same thing when it comes to the code generator. I think I'm going to fork this repo and try it out.

We consider psalm rules very ad hoc in this context so having a solid nullability correspondence with the actual Shopware API would be great. I think I might give it a go :)

from shopware-php-sdk.

solverat avatar solverat commented on July 19, 2024

Hey @vienthuong. It would be nice to have something like toArray() in Entity classes.

$product = new ProductEntity();
$product->active = true;

$productRepository->create($product->toArray(), $context); 

... which only should return populated fields. I've tried this by using the jsonSerialize method, but this method of course returns every available property populated with a null value if not set.

from shopware-php-sdk.

solverat avatar solverat commented on July 19, 2024

Maybe another one :):

https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyNjI1Mzkw-media-handling#upload-the-resource-directly

Uploading asset binaries via repository (?) would be nice. In some cases, URLs are not reachable from outside.

from shopware-php-sdk.

vienthuong avatar vienthuong commented on July 19, 2024

@solverat
Hi, sounds like a good idea, I created a new issue here #23
But honestly, I don't 100% get your expectation so can you write a bit more specific in the new ticket? Like why we need it and why it's not possible currently with the SDK :)
Thanks for contribution

from shopware-php-sdk.

jakub-groncki avatar jakub-groncki commented on July 19, 2024

Hi @vienthuong,

On my team we use psalm and sometimes it gets a little bit frustrating that all of the properties in entities are nullable/set to null by default. This either generates a lot of null-checking or disabling null checks in psalm altogether. I reckon that "fixing" or adjusting this wouldn't be a breaking change, right? It's a slight annoyance, especially when you don't normally expect a null value in Shopware:

// CurrencyEntity/SDK:

public ?string $symbol = null;


// CurrencyEntity/Shopware:

/**
 * @var string
 */
protected $symbol;

from shopware-php-sdk.

vienthuong avatar vienthuong commented on July 19, 2024

Hi @jakub-groncki
Sorry for the late response.
Change the nullable to non nullable is breaking change unfortunately. By default it's all nullable so we can set all the properties with value or null without fatal error. I already considered it in the generator script but for some reason I commented it out so I am not sure that add it back is a safe solution.

image

https://github.com/vienthuong/shopware-php-sdk/blob/master/script/src/CodeGenerator.php

I'd recommend ignore these psalm rule using some regex pattern if possible. Or feel free to create a MR to update the CodeGenerator if you find it useful :)

from shopware-php-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.