public function testProductMetafields() { $product = new \erdiko\shopify\models\Product(); $data = $product->getProducts(); $this->assertTrue(count($data) > 0, "There should be atleast one product to\n\t\t \tcontinue this test"); $pId = $data[0]['id']; $this->assertTrue(!empty($pId), "Product id is empty"); // create $args = array("metafield" => array("namespace" => $this->meta->getNamespace(), "key" => "test_key", "value" => "test_value", "value_type" => "string")); $resp = $this->meta->setProductMetaField($pId, $args); $this->assertTrue(!empty($resp), "empty response"); $metaID = $resp['id']; $this->assertTrue(!empty($metaID), "metafield id is empty"); $metaResp = $this->meta->getProductMetaFieldByID($pId, $metaID); $this->assertTrue(strcmp($metaResp['key'], 'test_key') == 0); $this->assertTrue(strcmp($metaResp['value'], 'test_value') == 0); $this->assertTrue($metaResp['id'] == $metaID); //update $args = array("metafield" => array("id" => $metaID, "value" => "test_value_2", "value_type" => "string")); $resp = $this->meta->updateProductMetaField($pId, $metaID, $args); $this->assertTrue(!empty($resp), "empty response"); $metaID = $resp['id']; $this->assertTrue(!empty($metaID), "metafield id is empty"); $metaResp = $this->meta->getProductMetaFieldByID($pId, $metaID); $this->assertTrue(strcmp($metaResp['key'], 'test_key') == 0); $this->assertTrue(strcmp($metaResp['value'], 'test_value_2') == 0); $this->assertTrue($metaResp['id'] == $metaID); // delete $this->meta->deleteProductMetaField($pId, $metaID, array()); $pMetaData = $this->meta->getProductMetaFields($pId); foreach ($pMetaData as $data) { $this->assertFalse($data['id'] == $metaID, "metafield not deleted !"); } }
/** * Get Product */ public function getProducts() { $product = new \erdiko\shopify\models\Product(); $data = $product->getProducts(); $this->setTitle('Shopify Product Grid'); $this->setContent($this->getLayout('grid/shopify', $data, dirname(__DIR__))); }
/** * Get Product */ public function getProducts() { $product = new \erdiko\shopify\models\Product(); $message = ""; $isError = FALSE; try { $data = $product->getProducts(); } catch (ShopifyApiException $e) { $response_headers = $e->getResponseHeaders(); $message = "Error in getting product list :: " . $response_headers['http_status_code'] . ":" . $response_headers['http_status_message']; $isError = TRUE; } catch (ShopifyCurlException $e) { $message = "Error :: Shopify Curl Exception"; $isError = TRUE; } catch (\Exception $e) { $message = $e->getMessage(); $isError = TRUE; } if (!$isError) { $this->setTitle('Shopify Product Grid'); $this->setContent($this->getLayout('grid/shopify', $data, dirname(__DIR__))); } else { $this->setContent($this->getLayout('message', $message, dirname(__DIR__))); } }