예제 #1
0
 /**
  *
  */
 private function retrieveBlogArticlesHelper($blogID, $type)
 {
     $blog = new \erdiko\shopify\models\Blog();
     $data = $blog->getBlogArticles($blogID);
     $message = "";
     $isError = FALSE;
     try {
         $data = $blog->getBlogArticles($blogID);
     } catch (ShopifyApiException $e) {
         $response_headers = $e->getResponseHeaders();
         $message = "Error in adding Metafield :: " . $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('Blog Articles');
         array_push($data, $blogID);
         if (!strcmp($type, "articleInfoPage")) {
             $this->setContent($this->getLayout('grid/listArticlesPage2', $data, dirname(__DIR__)));
         } else {
             $this->setContent($this->getLayout('grid/listArticles', $data, dirname(__DIR__)));
         }
     } else {
         $this->setContent($this->getLayout('message', $message, dirname(__DIR__)));
     }
 }
예제 #2
0
 public function testArticleMetafields()
 {
     $blog = new \erdiko\shopify\models\Blog();
     $data = $blog->getBlogs();
     $this->assertTrue(count($data) > 0, "There should be atleast one blog to\n\t\t \tcontinue this test");
     $bId = $data[0]['id'];
     $this->assertTrue(!empty($bId), "Blog id is empty");
     $articles = $blog->getBlogArticles($bId);
     $this->assertTrue(count($data) > 0, "There should be atleast one article to\n\t\t \tcontinue this test");
     $aId = $articles[0]['id'];
     $this->assertTrue(!empty($aId), "Article id is empty");
     // create
     $args = array("article" => array("id" => $aId, "metafields" => array(array("key" => "test_article_key", "value" => "test_article_value", "value_type" => "string", "namespace" => $this->meta->getNamespace()))));
     $this->meta->setBlogArticleMetaField($bId, $aId, $args);
     $articlesMeta = $this->meta->getBlogArticleMetaFields($aId);
     $metaResp = "";
     $metaID = 0;
     foreach ($articlesMeta as $metaResp) {
         if (strcmp($metaResp['key'], "test_article_key") == 0) {
             $metaID = $metaResp['id'];
             $this->assertTrue(strcmp($metaResp['value'], 'test_article_value') == 0);
         }
     }
     $this->assertTrue($metaID != 0, "metafield is not set");
     //update
     $args = array("metafield" => array("id" => $metaID, "value" => "test_article_value_1", "value_type" => "string"));
     $resp = $this->meta->updateBlogArticleMetaField($aId, $metaID, $args);
     $articlesMeta = $this->meta->getBlogArticleMetaFields($aId);
     $metaResp = "";
     $metaID = 0;
     foreach ($articlesMeta as $metaResp) {
         if (strcmp($metaResp['key'], "test_article_key") == 0) {
             $metaID = $metaResp['id'];
             $this->assertTrue(strcmp($metaResp['value'], 'test_article_value_1') == 0);
         }
     }
     $this->assertTrue($metaID != 0, "metafield is not set");
     // delete
     $this->meta->deleteBlogArticleMetaField($bId, $metaID, array());
     $articlesMeta = $this->meta->getBlogArticleMetaFields($aId);
     foreach ($articlesMeta as $data) {
         $this->assertFalse($data['id'] == $metaID, "metafield not deleted !");
     }
 }