Skip to content

Commit

Permalink
Merge branch 'v1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
husseinalhammad committed Dec 4, 2018
2 parents 0f972c3 + 5b4544a commit 796995f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pipit_catalog/_version.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
if (!defined('PIPIT_CATALOG_VERSION')) define('PIPIT_CATALOG_VERSION', '1.2.1');
if (!defined('PIPIT_CATALOG_VERSION')) define('PIPIT_CATALOG_VERSION', '1.3');
5 changes: 5 additions & 0 deletions pipit_catalog/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@
$Settings = $API->get('Settings');

$this->add_create_page('catalog_app', 'list');


$app_path = $API->app_path();
$Perch = Perch::fetch();
$Perch->add_javascript("$app_path/assets/js/product_preview.js");
}
22 changes: 22 additions & 0 deletions pipit_catalog/assets/js/product_preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var pageUrl = window.location.href;


if(pageUrl.includes('apps/perch_shop_products/product/edit')) {
var url = new URL(window.location.href);
var id = url.searchParams.get("id");


// add button
var smartbar = document.querySelector('.smartbar ul');
var previewUrl = Perch.path+'/addons/apps/pipit_catalog/product_view.php?id='+id;

let html = `<li class="smartbar-end smartbar-util">
<a href="${previewUrl}" title="View" class="viewext" target="_blank" rel="noopener">
<svg role="img" width="14" height="14" class="icon icon-o-world" title="View Page" aria-label="View Page"> <use xlink:href="/perch/core/assets/svg/core.svg#o-world"></use> </svg>
<span>View</span>
</a>
</li>`

smartbar.insertAdjacentHTML('beforeend', html);

}
6 changes: 5 additions & 1 deletion pipit_catalog/lang/en-gb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@
"Cancel": "Cancel",
"Product orders successfully updated.": "Product orders successfully updated.",
"Order": "Order",
"Access the Catalog app": "Access the Catalog app"
"Access the Catalog app": "Access the Catalog app",
"Opps": "Opps",
"The product URL is not set, or the product could not be found.": "The product URL is not set, or the product could not be found.",
"Product Inactive": "Product Inactive",
"The product status is set to inactive. Inactive products cannot be viewed on the site.": "The product status is set to inactive. Inactive products cannot be viewed on the site."
}
56 changes: 56 additions & 0 deletions pipit_catalog/product_view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
include(__DIR__.'/../../../core/inc/api.php');


$API = new PerchAPI(1.0, 'pipit_catalog');
$HTML = $API->get('HTML');
$Settings = $API->get('Settings');


$ShopAPI = new PerchAPI(1, 'perch_shop');
$Products = new PerchShop_Products($ShopAPI);
$Settings = $API->get('Settings');


$Collection = false;

$item_id = $product_url = false;

// Find the collection

if (isset($_GET['id']) && is_numeric($_GET['id'])) {

$id = (int) $_GET['id'];
$Product = $Products->find($id);

$product_url = $Settings->get('perch_shop_product_url')->val();


$product_url = preg_replace_callback('/{([A-Za-z0-9_\-]+)}/', '_replace_vars', $product_url);


$view_page_url = rtrim($Settings->get('siteURL')->val(), '/').$product_url;
if($Product->status() == '1') {
PerchSystem::redirect($view_page_url);
}
}


function _replace_vars($matches)
{
global $Product;

if($matches) {
$value = $matches[1];
return $Product->$value();
}

}

include(PERCH_CORE . '/inc/top.php');
if($Product->status() != '1') {
echo $HTML->warning_block('Product Inactive', 'The product status is set to inactive. Inactive products cannot be viewed on the site.');
} else {
echo $HTML->warning_block('Opps', 'The product URL is not set, or the product could not be found.');
}
include(PERCH_CORE . '/inc/btm.php');

0 comments on commit 796995f

Please sign in to comment.