Skip to content

Instantly share code, notes, and snippets.

View paliarush's full-sized avatar

Alex Paliarush paliarush

View GitHub Profile
@paliarush
paliarush / OauthClient.php
Last active October 19, 2022 11:37 — forked from anupdugar/OauthClient.php
Scripts to demo Magento 2 Oauth1.a token exchange
<?php
use OAuth\Common\Consumer\Credentials;
use OAuth\Common\Http\Client\ClientInterface;
use OAuth\Common\Http\Exception\TokenResponseException;
use OAuth\Common\Http\Uri\Uri;
use OAuth\Common\Http\Uri\UriInterface;
use OAuth\Common\Storage\TokenStorageInterface;
use OAuth\OAuth1\Service\AbstractService;
use OAuth\OAuth1\Signature\SignatureInterface;

Running Magento 2 functional tests

  1. If not installed, download and install JDK: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  2. Download selenium server: https://www.seleniumhq.org/download/
  3. Run selenium filter: java -jar ~/Downloads/<name_of_the_selenium_executable>.jar
  4. [Automated in current vagrant box] Copy dev/tests/functional/phpunit.xml and change: app_frontend_url, app_backend_url (i.e. URL's of your storefront and admin page).
  5. [Automated in current vagrant box] Copy dev/tests/functional/etc/config.xml and change: application/backendLogin, application/backendPassword (i.e. admin username and password).
  6. Add the following custom server declarations to dev/tests/functional/etc/config.xml and use one of them at a time
    <server>

[POLL] Custom attributes in Magento GraphQL Schema

Magento GraphQL endpoints must support EAV entities such as Products. GraphQL specification requires all complex types eventually to be represented as structures of scalar types. Mixed/any types are not supported.

We have couple options to choose from and would be glad to hear your opinion on that.

Option 1: Custom attributes container

Schema

@paliarush
paliarush / extension_attributes_initialization.php
Last active May 25, 2018 14:36
No more boilerplate code for extension attributes object instantiation
<?php
// Before Magento 2.3
$extensionAttributes = $product->getExtensionAttributes();
if (null === $extensionAttributes) {
/** @var \Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes */
$extensionAttributes = $this->extensionAttributesFactory->create(ProductInterface::class);
$product->setExtensionAttributes($extensionAttributes);
}
$myExtensionAttribute = $extensionAttributes->getMyExtensionAttribute();
{
"$ref": "#/definitions/IoRuntimeComplexProductExtension",
"definitions": {
"IoRuntimeComplexProductExtension": {
"type": "object",
"title": "Complex product extension",
"description": "Complex product extension field",
"properties": {
"image": {
"type": "string"