Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Commands/Download Theme.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ require_once TM_BUNDLE_SUPPORT.DIRECTORY_SEPARATOR.'functions.php';

//Request Asset URL Template
// %1: API KEY, %2: PASSWORD, %3: STORE, %4: ASSET NAME
$requestUrlTemp = 'http://%1$s:%2$s@%3$s/admin/assets.json';
$requestUrl = sprintf($requestUrlTemp, $api_key, $password, $store);
if ($theme_id == "") {
$requestUrlTemp = 'http://%1$s:%2$s@%3$s/admin/assets.json';
$requestUrl = sprintf($requestUrlTemp, $api_key, $password, $store);
}
else {
$requestUrlTemp = 'http://%1$s:%2$s@%3$s/admin/themes/%4$s/assets.json';
$requestUrl = sprintf($requestUrlTemp, $api_key, $password, $store, $theme_id);
}

// yes, I am aware php has curl. This is just simpler.
echo "Getting theme asset list...<br>";
Expand Down Expand Up @@ -67,7 +73,7 @@ foreach ($assetFiles as $file) {
}

echo "Fetching {$file}...<br>";
$asset = get_asset($api_key, $password, $store, $file);
$asset = get_asset($api_key, $password, $store, $theme_id, $file);

if(false === $asset) {
echo "*Error fetching: ($file)<br>";
Expand Down
2 changes: 1 addition & 1 deletion Commands/Get Rendered CSS file from _css_liquid.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if(false !== strpos($filepath, '.css.liquid')) {

echo "Fetching {$filepath}...<br>";

$asset = get_asset($api_key, $password, $store, $filepath);
$asset = get_asset($api_key, $password, $store, $theme_id, $filepath);

if(false == $asset) { //Do Nothing.
echo '*Error: Could not get '. $filepath .'<br>';
Expand Down
2 changes: 1 addition & 1 deletion Commands/Remove Selected Assets from Shopify.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ foreach ($selectedFiles as $file) {
$assetKey = calc_asset_key($file);
echo "Removing $assetKey... ";

if(remove_asset($api_key, $password, $store, $assetKey)) {
if(remove_asset($api_key, $password, $store, $theme_id, $assetKey)) {
echo "removed¡<br>";
}
else {
Expand Down
2 changes: 1 addition & 1 deletion Commands/Update Selected Files From Shopify.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ foreach ($selectedFiles as $file) {
$assetKey = calc_asset_key($file);
echo "Fetching {$assetKey}...<br>";

$asset = get_asset($api_key, $password, $store, $assetKey);
$asset = get_asset($api_key, $password, $store, $theme_id, $assetKey);

if(false == $asset) { //Do Nothing.
echo '*Error: Could not update asset '. $assetKey .'<br>';
Expand Down
2 changes: 1 addition & 1 deletion Commands/Update Template From Shopify.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require_once TM_BUNDLE_SUPPORT.DIRECTORY_SEPARATOR.'functions.php';
// File path, based on theme restriction of no nested folder, so we make certain assumptions
$filepath = calc_asset_key(getenv('TM_FILEPATH'));

$asset = get_asset($api_key, $password, $store, $filepath);
$asset = get_asset($api_key, $password, $store, $theme_id, $filepath);

// clean out the \r 's - mac uses \n only.
if(false !== $asset && property_exists($asset, 'value')) {
Expand Down
2 changes: 1 addition & 1 deletion Support/assets/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$xmlFile = tempnam('/tmp', 'foo').'.xml';
file_put_contents($xmlFile, $reqData);

$response = send_asset($api_key, $password, $store ,$xmlFile);
$response = send_asset($api_key, $password, $store , $theme_id, $xmlFile);

if('200' == $response) {
echo "Uploaded {$assetKey} to {$config->current}.";
Expand Down
2 changes: 1 addition & 1 deletion Support/assets/upload_multi.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
file_put_contents($xmlFile, $reqData);

echo "Sending asset: {$assetKey}...<br>";
$response = send_asset($api_key, $password, $store ,$xmlFile);
$response = send_asset($api_key, $password, $store , $theme_id, $xmlFile);

if('200' == $response) {
echo "Uploaded: {$assetKey}<br>";
Expand Down
3 changes: 3 additions & 0 deletions Support/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class mConfig {

var $store = null;

var $theme_id = null;

//Used to output to user what shop they are pushing to. Reads better than full shop name.
var $current = 'default';

Expand All @@ -33,6 +35,7 @@ function __construct($path) {
$this->api_key = getenv('SHOPIFY_API_KEY');
$this->password = getenv('SHOPIFY_PASSWORD');
$this->store = getenv('SHOPIFY_STORE');
$this->theme_id = getenv('SHOPIFY_THEME_ID');

if( (!$this->api_key) || (!$this->password) || (!$this->store) ) {
echo "No config file found here: {$path} ?";
Expand Down
45 changes: 33 additions & 12 deletions Support/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ function output_error($response, $options = array()) {
* @param string $key Key of asset we are downloading
* @return object Asset / false on failure
**/
function get_asset($api_key, $password, $store, $key) {
function get_asset($api_key, $password, $store, $theme_id, $key) {
//Request Asset URL Template
// %1: API KEY, %2: PASSWORD, %3: STORE, %4: ASSET NAME
$requestUrl = sprintf('http://%1$s:%2$s@%3$s/admin/assets.json?asset[key]=%4$s',
$api_key, $password, $store, $key
);
if ($theme_id == "") {
$requestUrl = sprintf('http://%1$s:%2$s@%3$s/admin/assets.json?asset[key]=%4$s',
$api_key, $password, $store, $key
);
}
else {
$requestUrl = sprintf('http://%1$s:%2$s@%3$s/admin/themes/%4$s/assets.json?asset[key]=%5$s',
$api_key, $password, $store, $theme_id, $key
);
}

$responseTxt = `curl -s -g '$requestUrl'`;
$response = json_decode($responseTxt);
Expand All @@ -83,11 +90,18 @@ function get_asset($api_key, $password, $store, $key) {
* @param string $xmlFile Path to the XML File with the contents to upload.
* @return string
**/
function send_asset($api_key, $password, $store ,$xmlFile) {
function send_asset($api_key, $password, $store, $theme_id, $xmlFile) {

$requestUrl = sprintf('http://%1$s:%2$s@%3$s/admin/assets.xml',
$api_key, $password, $store
);
if ($theme_id == "") {
$requestUrl = sprintf('http://%1$s:%2$s@%3$s/admin/assets.xml',
$api_key, $password, $store
);
}
else {
$requestUrl = sprintf('http://%1$s:%2$s@%3$s/admin/themes/%4$s/assets.xml',
$api_key, $password, $store, $theme_id
);
}

// Right now, not bothering with dumping the full response/error handling. Will add if it becomes an issue.
//We just collect the http_code and will display message if it's Not 200
Expand All @@ -105,12 +119,19 @@ function send_asset($api_key, $password, $store ,$xmlFile) {
* @param string $key Key of asset we are downloading
* @return object Asset / false on failure
**/
function remove_asset($api_key, $password, $store, $key) {
function remove_asset($api_key, $password, $store, $theme_id, $key) {
//Request Asset URL Template
// %1: API KEY, %2: PASSWORD, %3: STORE, %4: ASSET NAME
$requestUrl = sprintf('http://%1$s:%2$s@%3$s/admin/assets.json?asset[key]=%4$s',
$api_key, $password, $store, $key
);
if ($theme_id == "") {
$requestUrl = sprintf('http://%1$s:%2$s@%3$s/admin/assets.json?asset[key]=%4$s',
$api_key, $password, $store, $key
);
}
else {
$requestUrl = sprintf('http://%1$s:%2$s@%3$s/admin/themes/%4$s/assets.json?asset[key]=%5$s',
$api_key, $password, $store, $theme_id, $key
);
}

$response = json_decode(`curl -w'%{http_code}' -X DELETE -s -g '$requestUrl'`);

Expand Down
1 change: 1 addition & 0 deletions Support/vars.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$api_key = $config->api_key; //getenv('SHOPIFY_API_KEY');
$password = $config->password; //getenv('SHOPIFY_PASSWORD');
$store = $config->store; //getenv('SHOPIFY_STORE');
$theme_id = $config->theme_id;

define('TM_PROJECT_DIRECTORY',getenv('TM_PROJECT_DIRECTORY'));

Expand Down