Skip to content

Conversation

@zackkatz
Copy link
Contributor

You can now work with Custom Fields.

use Bigcommerce\Api\Client as Bigcommerce;

$Product = Bigcommerce::getProduct(1);

// Get a collection of Custom Fields for the product ID
Bigcommerce::getProductCustomFields($Product->id);

// Get the Custom Field with the ID #5 for the product ID
Bigcommerce::getProductCustomField($Product->id, 5);

// Create a Custom Field for the product ID
$id = Bigcommerce::createProductCustomField($Product->id, array(
    'name'  =>  'Name of Custom Field',
    'text'  =>  'Value of Custom Field'
));

// Delete the Custom Field with the ID #5 for the product ID
Bigcommerce::deleteProductCustomField($Product->id, 5);

// Or you can do it like other resources as well.
$CustomField = new Bigcommerce\Api\Resources\ProductCustomField(array(
    'name'  =>  'Name of Custom Field',
    'text'  =>  'Value of Custom Field',
    'product_id' => 1 // The ID of the attached product
));
$CustomField->create();

You can now work with Custom Fields.

`
use Bigcommerce\Api\Client as Bigcommerce;

$Product = Bigcommerce::getProduct(1);

// Get a collection of Custom Fields for the product ID
Bigcommerce::getProductCustomFields($Product->id);

// Get the Custom Field with the ID bigcommerce#5 for the product ID
Bigcommerce::getProductCustomField($Product->id, 5);

// Create a Custom Field for the product ID
$id = Bigcommerce::createProductCustomField($Product->id, array(
	'name'	=>	'Name of Custom Field',
	'text'	=>	'Value of Custom Field'
));

// Delete the Custom Field with the ID bigcommerce#5 for the product ID
Bigcommerce::deleteProductCustomField($Product->id, 5);

// Or you can do it like other resources as well.
$CustomField = new Bigcommerce\Api\Resources\ProductCustomField(array(
	'name'	=>	'Name of Custom Field',
	'text'	=>	'Value of Custom Field',
	'product_id' => 1 // The ID of the attached product
));

$CustomField->create();
`
@maetl
Copy link
Contributor

maetl commented Sep 30, 2013

👍

maetl added a commit that referenced this pull request Sep 30, 2013
Allow creating/updating/deleting custom fields
@maetl maetl merged commit 4675693 into bigcommerce:master Sep 30, 2013
@zackkatz
Copy link
Contributor Author

zackkatz commented Oct 1, 2013

What error do you get?

@zackkatz
Copy link
Contributor Author

zackkatz commented Oct 1, 2013

You need to print or echo it. It doesn't necessarily mean that there's an error. Use the new getProductCustomField method instead.

public function display()
{
echo Client::getProductCustomField($this->product_id, $this->id);
}

@zackkatz
Copy link
Contributor Author

zackkatz commented Oct 1, 2013

Well your product may have no custom fields…try:

print_r(Client::getProductCustomFields($Product->id));

@zackkatz
Copy link
Contributor Author

zackkatz commented Oct 1, 2013

Sorry, I can't help you there.

@jpedraza
Copy link

jpedraza commented Oct 1, 2013

No luck I created a new php page just to display custom field using u code and added a custom field to a product. Display product name, sku but not custom field thanks

On Oct 1, 2013, at 1:50 PM, zackkatz [email protected] wrote:

Well your product may have no custom fields…try:

print_r(Client::getProductCustomFields($Product->id));


Reply to this email directly or view it on GitHub.

@zackkatz
Copy link
Contributor Author

In the example, 5 is the ID of the custom field. I'm not sure why it wouldn't work for you in your example.

@coreybullman
Copy link

I'm using the API to update custom fields for a product and I'm getting this error:

Object of class stdClassà�K´cðËÛ could not be converted to string

Here's my code:

Bigcommerce::updateProductCustomField( $id, $custom_field_id, array(
    'name' => 'Core Price',
    'text' => '900'
) );

It is updating the product. I'm just trying to figure out where that error is coming from. Thanks!

@prabukaran
Copy link

Hi

i would like to get some products in my Bigcommerce store based on date using api. So i have followed the following api code like this. But no luck

$filter = array('date_created' => 'Sat, 25 Jan 2014 16:43:15 +0000');//query filter

$products = Bigcommerce::getProducts($filter);

But in the same way following one is working good.

$filter = array('sku' => 'CST-120');//query filter

$products = Bigcommerce::getProducts($filter);

So please any help me how can i change the date variable would be better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants