Skip to content

Commit

Permalink
Renaming to match Shopify docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gnikyt committed Oct 21, 2018
1 parent 313e322 commit a80aeca
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 31 deletions.
63 changes: 63 additions & 0 deletions README.md
Expand Up @@ -44,6 +44,69 @@ $collect = Collect::all(['collection_id' => $collection->id]);
$products = $collect->map(function ($c) { return $c->product; });
```

## Status

11.4% completed

- [ ] AccessScope
- [ ] StorefrontAccessToken
- [ ] Policy
- [ ] ShippingZone
- [ ] Province
- [ ] Country
- [ ] Shop
- [ ] AbandonedCheckout
- [ ] DraftOrder
- [ ] Order
- [ ] OrderRisk
- [ ] Refund
- [ ] Transaction
- [ ] Payouts
- [ ] Balance
- [ ] Transactions
- [x] Collect
- [x] Product
- [ ] SmartCollection
- [x] ProductImage
- [x] ProductVariant
- [x] CustomCollection
- [ ] Webhook
- [ ] Event
- [ ] CustomerAddress
- [ ] Customer
- [ ] CustomerSavedSearch
- [ ] User
- [ ] Multipass
- [ ] GiftCard
- [ ] ShopifyQL
- [ ] Report
- [ ] PriceRule
- [ ] DiscountCode
- [ ] Checkout
- [ ] ResourceFeedback
- [ ] ProductListing
- [ ] CollectionListing
- [ ] Payment
- [ ] InventoryItem
- [ ] Location
- [ ] InventoryLevel
- [ ] CarrierService
- [ ] FulfillmentEvent
- [ ] Fulfillment
- [ ] FulfillmentService
- [ ] Theme
- [ ] Page
- [ ] Comment
- [ ] Asset
- [ ] Blog
- [ ] Redirect
- [ ] ScriptTag
- [ ] BlogArticle
- [ ] UsageCharge
- [ ] ApplicationCredit
- [ ] ApplicationCharge
- [ ] RecurringApplicationCharge

## Testing

Run `bin/phpunit --no-coverage` for tests.
Expand Down
2 changes: 2 additions & 0 deletions src/OhMyBrew/BasicShopifyResource/Models/Collect.php
Expand Up @@ -4,6 +4,8 @@

use OhMyBrew\BasicShopifyResource\Relationships\HasOne;
use OhMyBrew\BasicShopifyResource\Resource;
use OhMyBrew\BasicShopifyResource\Models\Product;
use OhMyBrew\BasicShopifyResource\Models\CustomCollection;

/**
* Custom Collection API.
Expand Down
Expand Up @@ -4,6 +4,7 @@

use OhMyBrew\BasicShopifyResource\Relationships\HasMany;
use OhMyBrew\BasicShopifyResource\Resource;
use OhMyBrew\BasicShopifyResource\Models\Collect;

/**
* Custom Collection API.
Expand Down
8 changes: 6 additions & 2 deletions src/OhMyBrew/BasicShopifyResource/Models/Product.php
Expand Up @@ -5,6 +5,10 @@
use OhMyBrew\BasicShopifyResource\Relationships\HasMany;
use OhMyBrew\BasicShopifyResource\Relationships\IncludesMany;
use OhMyBrew\BasicShopifyResource\Resource;
use OhMyBrew\BasicShopifyResource\Models\ProductVariant;
use OhMyBrew\BasicShopifyResource\Models\ProductImage;
use OhMyBrew\BasicShopifyResource\Models\Collect;
use OhMyBrew\BasicShopifyResource\Models\CustomCollection;

/**
* Product API.
Expand Down Expand Up @@ -40,8 +44,8 @@ class Product extends Resource
public function __construct()
{
$this->relationships = [
'variants' => new IncludesMany(Variant::class),
'images' => (new IncludesMany(Image::class))->setParams(
'variants' => new IncludesMany(ProductVariant::class),
'images' => (new IncludesMany(ProductImage::class))->setParams(
/**
* @codeCoverageIgnore
*/
Expand Down
Expand Up @@ -4,11 +4,12 @@

use OhMyBrew\BasicShopifyResource\Relationships\HasOne;
use OhMyBrew\BasicShopifyResource\Resource;
use OhMyBrew\BasicShopifyResource\Models\Product;

/**
* Image API.
* ProductImage API.
*/
class Image extends Resource
class ProductImage extends Resource
{
/**
* The resource path part.
Expand Down
Expand Up @@ -5,8 +5,13 @@
use OhMyBrew\BasicShopifyResource\Relationships\HasOne;
use OhMyBrew\BasicShopifyResource\Relationships\HasOneThrough;
use OhMyBrew\BasicShopifyResource\Resource;
use OhMyBrew\BasicShopifyResource\Models\ProductImage;
use OhMyBrew\BasicShopifyResource\Models\Product;

class Variant extends Resource
/**
* ProductVariant API.
*/
class ProductVariant extends Resource
{
/**
* The resource path part.
Expand Down Expand Up @@ -45,7 +50,7 @@ function () {
return ['product_id' => $this->product_id];
}
),
'image' => (new HasOneThrough(Image::class))
'image' => (new HasOneThrough(ProductImage::class))
->setThrough(Product::class)
->setThroughId(
/**
Expand Down
12 changes: 6 additions & 6 deletions test/Models/ImageTest.php → test/Models/ProductImageTest.php
Expand Up @@ -2,7 +2,7 @@

namespace OhMyBrew\BasicShopifyResource\Test\Models;

use OhMyBrew\BasicShopifyResource\Models\Image;
use OhMyBrew\BasicShopifyResource\Models\ProductImage;
use OhMyBrew\BasicShopifyResource\Models\Product;
use OhMyBrew\BasicShopifyResource\Test\TestCase;
use Tightenco\Collect\Support\Collection;
Expand All @@ -11,7 +11,7 @@ class ImageTest extends TestCase
{
public function testSetup()
{
$props = $this->getResourceProperties(new Image());
$props = $this->getResourceProperties(new ProductImage());

$this->assertEquals('images', $props->resourcePath);
$this->assertEquals('image', $props->resourceName);
Expand All @@ -22,15 +22,15 @@ public function testSetup()
public function testFinders()
{
$connection = $this->createConnection(['models/image', 'models/images']);
$image = $this->invokeMethod(Image::class, 'find', [850703190]);
$image = $this->invokeMethod(ProductImage::class, 'find', [850703190]);

$this->assertEquals(
'/admin/images/850703190.json',
$this->getLastPathCalled($connection)
);
$this->assertInstanceOf(Image::class, $image);
$this->assertInstanceOf(ProductImage::class, $image);

$images = $this->invokeMethod(Image::class, 'all');
$images = $this->invokeMethod(ProductImage::class, 'all');

$this->assertEquals(
'/admin/images.json',
Expand All @@ -42,7 +42,7 @@ public function testFinders()
public function testRelationships()
{
$connection = $this->createConnection(['models/image', 'models/products']);
$image = $this->invokeMethod(Image::class, 'find', [850703190]);
$image = $this->invokeMethod(ProductImage::class, 'find', [850703190]);

// Product (API call)
$product = $image->product;
Expand Down
Expand Up @@ -2,17 +2,17 @@

namespace OhMyBrew\BasicShopifyResource\Test\Models;

use OhMyBrew\BasicShopifyResource\Models\Image;
use OhMyBrew\BasicShopifyResource\Models\ProductImage;
use OhMyBrew\BasicShopifyResource\Models\Product;
use OhMyBrew\BasicShopifyResource\Models\Variant;
use OhMyBrew\BasicShopifyResource\Models\ProductVariant;
use OhMyBrew\BasicShopifyResource\Test\TestCase;
use Tightenco\Collect\Support\Collection;

class VariantTest extends TestCase
class ProductVariantTest extends TestCase
{
public function testSetup()
{
$props = $this->getResourceProperties(new Variant());
$props = $this->getResourceProperties(new ProductVariant());

$this->assertEquals('variants', $props->resourcePath);
$this->assertEquals('variant', $props->resourceName);
Expand All @@ -24,15 +24,15 @@ public function testFinders()
{
$connection = $this->createConnection(['models/product', 'models/variant', 'models/variants']);
$product = $this->invokeMethod(Product::class, 'find', [632910392]);
$variant = $this->invokeMethod(Variant::class, 'findThrough', [808950810, $product]);
$variant = $this->invokeMethod(ProductVariant::class, 'findThrough', [808950810, $product]);

$this->assertEquals(
'/admin/products/632910392/variants/808950810.json',
$this->getLastPathCalled($connection)
);
$this->assertInstanceOf(Variant::class, $variant);
$this->assertInstanceOf(ProductVariant::class, $variant);

$variants = $this->invokeMethod(Variant::class, 'allThrough', [$product]);
$variants = $this->invokeMethod(ProductVariant::class, 'allThrough', [$product]);

$this->assertEquals(
'/admin/products/632910392/variants.json',
Expand All @@ -51,14 +51,14 @@ public function testRelationships()
'models/image',
]);
$product = $this->invokeMethod(Product::class, 'find', [632910392]);
$variant = $this->invokeMethod(Variant::class, 'findThrough', [808950810, $product]);
$variant = $this->invokeMethod(ProductVariant::class, 'findThrough', [808950810, $product]);

// Product (API call)
$product = $variant->product;
$this->assertInstanceOf(Product::class, $product);

// Image (API call)
$image = $variant->image;
$this->assertInstanceOf(Image::class, $image);
$this->assertInstanceOf(ProductImage::class, $image);
}
}
10 changes: 5 additions & 5 deletions test/Resource/ResourceFindTest.php
Expand Up @@ -3,7 +3,7 @@
namespace OhMyBrew\BasicShopifyResource\Test\Resource;

use OhMyBrew\BasicShopifyResource\Models\Product;
use OhMyBrew\BasicShopifyResource\Models\Variant;
use OhMyBrew\BasicShopifyResource\Models\ProductVariant;
use OhMyBrew\BasicShopifyResource\Resource;
use OhMyBrew\BasicShopifyResource\Test\TestCase;
use Tightenco\Collect\Support\Collection;
Expand All @@ -29,16 +29,16 @@ public function testFindThrough()

// Find through resource
$connection = $this->createConnection(['base/variant_find_through', 'base/variant_find_through']);
$variant = $this->invokeMethod(Variant::class, 'findThrough', [808950810, $product]);
$variant = $this->invokeMethod(ProductVariant::class, 'findThrough', [808950810, $product]);

$this->assertEquals(
'/admin/products/632910392/variants/808950810.json',
$this->getLastPathCalled($connection)
);
$this->assertInstanceOf(Variant::class, $variant);
$this->assertInstanceOf(ProductVariant::class, $variant);

// Find through string
$variant = $this->invokeMethod(Variant::class, 'findThrough', [808950810, 'products/632910392']);
$variant = $this->invokeMethod(ProductVariant::class, 'findThrough', [808950810, 'products/632910392']);

$this->assertEquals(
'/admin/products/632910392/variants/808950810.json',
Expand All @@ -62,7 +62,7 @@ public function testAllThrough()
{
$connection = $this->createConnection(['base/product_find', 'base/variant_all']);
$product = $this->invokeMethod(Product::class, 'find', [632910392]);
$variants = $this->invokeMethod(Variant::class, 'allThrough', [$product]);
$variants = $this->invokeMethod(ProductVariant::class, 'allThrough', [$product]);

$this->assertEquals(
'/admin/products/632910392/variants.json',
Expand Down
4 changes: 2 additions & 2 deletions test/Resource/ResourceRelationsTest.php
Expand Up @@ -3,7 +3,7 @@
namespace OhMyBrew\BasicShopifyResource\Test\Resource;

use OhMyBrew\BasicShopifyResource\Models\Product;
use OhMyBrew\BasicShopifyResource\Models\Variant;
use OhMyBrew\BasicShopifyResource\Models\ProductVariant;
use OhMyBrew\BasicShopifyResource\Test\TestCase;
use Tightenco\Collect\Support\Collection;

Expand Down Expand Up @@ -54,7 +54,7 @@ public function testHasOneRelationship()
{
// Product does not exist for variant in the response, so an API call should be made
$connection = $this->createConnection(['base/variant_find', 'base/product_all']);
$variant = $this->invokeMethod(Variant::class, 'find', [908950810]);
$variant = $this->invokeMethod(ProductVariant::class, 'find', [908950810]);

$this->assertInstanceOf(Product::class, $variant->product);
$this->assertEquals(
Expand Down
6 changes: 3 additions & 3 deletions test/Resource/ResourceTest.php
Expand Up @@ -4,7 +4,7 @@

use OhMyBrew\BasicShopifyAPI;
use OhMyBrew\BasicShopifyResource\Models\Product;
use OhMyBrew\BasicShopifyResource\Models\Variant;
use OhMyBrew\BasicShopifyResource\Models\ProductVariant;
use OhMyBrew\BasicShopifyResource\Test\TestCase;
use ReflectionClass;

Expand Down Expand Up @@ -61,7 +61,7 @@ public function testProperties()
$this->assertEquals('IPod Nano - 8GB', $product->title);

// Test setting a relational property
$variant = new Variant();
$variant = new ProductVariant();

$this->assertNull($variant->product_id);
$variant->product = $product;
Expand All @@ -73,7 +73,7 @@ public function testProperties()
*/
public function testThrowsErrorTryingToSetInvalidRelational()
{
$variant = new Variant();
$variant = new ProductVariant();
$variant->product = 1;
}

Expand Down

0 comments on commit a80aeca

Please sign in to comment.