Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Updated API response cpc values and new category ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothymarois committed Sep 5, 2018
1 parent ced9775 commit 906e034
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 24 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Release Notes


## v1.0.6 (09/05/2018)

### Added
* Added `aecpc()` method using the `['aecpc']` on the product array.
* Added `categoryId()` method to `Product` class.
* Added `['category_id']` to the `Product` array.
* Added `getCategoryWithIds()` method on the `Results` class

### Changed
* Change the `cpc()` method to `ecpc()` using the `['ecpc']`


## v1.0.5 (08/28/2018)

### Changed
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ $brands = $results->getBrands();

// get a list of the brands in the results
$categories = $results->getCategories();

```

## Results:
Expand All @@ -59,6 +60,7 @@ Using the `query()` method returns `Baseify\Api\ProductSearch\Results`
|`getStores()` | Get an `array` of stores (pulled from products) |
|`getBrands()` | Get an `array` of brands (pulled from products) |
|`getCategories()` | Get an `array` of categories (pulled from products) |
|`getCategoryWithIds()` | Get the categories and the category ids |
|`getProducts()` | Get products returned as a `Collection` object |
|`toArray()` | Get an array of entire results |

Expand Down
26 changes: 24 additions & 2 deletions src/Api/ProductSearch/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ public function brand()
}


/**
* categoryId
*
*/
public function categoryId()
{
return (($this->productArray['category_id']) ?? '');
}


/**
* category
*
Expand Down Expand Up @@ -184,15 +194,25 @@ public function raw()


/**
* eCPC
* aecpc
*
*/
public function ecpc()
public function aecpc()
{
return ($this->productArray['aecpc']) ?? 0;
}


/**
* ecpc
*
*/
public function ecpc()
{
return ($this->productArray['ecpc']) ?? 0;
}


/**
* toArray
*
Expand All @@ -209,12 +229,14 @@ public function toArray()
'price' => $this->price(),
'list_price' => $this->listPrice(),
'ecpc' => $this->ecpc(),
'aecpc' => $this->aecpc(),
'currency' => $this->currency(),
'brand' => $this->brand(),
'store_name' => $this->storeName(),
'store_link' => $this->storeLink(),
'store_image' => $this->storeImage(),
'category' => $this->categoryName(),
'category_id' => $this->categoryId(),
'free_shipping' => $this->isFreeShipping()
];
}
Expand Down
26 changes: 22 additions & 4 deletions src/Api/ProductSearch/Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class Results
*/
protected $categories = [];

/**
* $categoryIds
*
* @return array
*/
protected $categoryIds = [];


/**
* $stores
Expand Down Expand Up @@ -174,6 +181,16 @@ public function getCategories()
}


/**
* getCategoryWithIds
*
*/
public function getCategoryWithIds()
{
return array_filter($this->categoryIds);
}


/**
* getProducts
*
Expand Down Expand Up @@ -228,6 +245,11 @@ protected function BuildFilterList()

if ($product->categoryName() != '')
{
// lets store the category ID + category Name in this array
$this->categoryIds[$product->categoryId()] = $product->categoryName();

// lets store the category and their product counts
// we can use this for filters/display for the user
if (!isset($this->categories[$product->categoryName()])) {
$this->categories[$product->categoryName()] = 1;
}
Expand All @@ -238,8 +260,6 @@ protected function BuildFilterList()
}
}



/**
* toArray
*
Expand All @@ -255,7 +275,6 @@ public function toArray()
return $products;
}


/**
* __toString
*
Expand All @@ -265,5 +284,4 @@ public function __toString()
return json_encode($this->toArray(), 1);
}


}
31 changes: 13 additions & 18 deletions tests/ProductSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,34 @@ class ProductSearchTest extends \PHPUnit\Framework\TestCase

public function testSetup()
{
$testIp = '45.248.78.5';
$testIp = '173.92.179.208';
$testAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36';

$baseify = (new Baseify('28a0fd38a28698b4788fcd882544bd16'))->productSearch([
'domain' => 'discount-savings.com'
$baseify = (new Baseify('ba7c6b686c25e6ac8bddefc948d40d4e'))->productSearch([
'domain' => 'discount-savings.com',
'widget' => 'test'
]);

$baseify->user()->set('ip',$testIp);
$baseify->user()->set('ua',$testAgent);
$baseify->filter()->set('limit',999);
$baseify->filter()->set('limit',99);

$results = $baseify->query('Matte Lipcolor');

// print_r($results->getEndpoint());

// print_r($results->getRaw());

$status = $results->getStatus();
$products = $results->getProducts();

$stores = $results->getStores();
// print_r($stores);

$brands = $results->getBrands();
// print_r($brands);

$categories = $results->getCategories();
// print_r($categories);
$status = $results->getStatus();
$products = $results->getProducts();
$stores = $results->getStores();
$brands = $results->getBrands();
$categories = $results->getCategories();
$categoryIds = $results->getCategoryWithIds();
// print_r($categoryIds);

print_r($products->all());

$this->assertEquals(true, $status);
// $this->assertEquals(9, $products->count());
$this->assertInternalType('object', $products);
$this->assertInternalType('array', $products->all());
$this->assertInstanceOf(Collection::class, $products);
Expand All @@ -55,7 +50,7 @@ public function testBad()
$testIp = '127.0.0.1';
$testAgent = 'Test';

$baseify = (new Baseify('28a0fd38a28698b4788fcd882544bd16'))->productSearch();
$baseify = (new Baseify('ba7c6b686c25e6ac8bddefc948d40d4e'))->productSearch();

$baseify->user()->set('ip',$testIp);
$baseify->user()->set('ua',$testAgent);
Expand Down

0 comments on commit 906e034

Please sign in to comment.