Skip to content
Permalink
Browse files

Product Box styling and fixed the way JSON was parsed when loading a …

…product box for editing.
  • Loading branch information...
MJGrant committed Jun 16, 2019
1 parent 3ed3f34 commit f1b7c6127726f1256fd5ce907c22c8009bf78717
Showing with 88 additions and 13 deletions.
  1. +27 −12 amazin-product-box/amazin-product-box.php
  2. +1 −1 amazin-product-box/scripts.js
  3. +60 −0 amazin-product-box/styles.css
@@ -17,25 +17,37 @@
add_action( 'wp_ajax_amazin_get_existing_post', 'amazin_get_existing_post' );
$jsurl = plugin_dir_url(__FILE__) . 'scripts.js';
wp_enqueue_script('scripts', $jsurl, array('jquery'), 1.61);
wp_enqueue_script('scripts', $jsurl, array('jquery'), 1.64);
wp_localize_script('scripts', 'MyAjax', array('ajaxurl' => admin_url('admin-ajax.php') ) );
} else {
// non-admin enqueues, actions, and filters
}
$cssurl = plugin_dir_url(__FILE__) . 'styles.css';
wp_enqueue_style( 'amazin-stylesheet', $cssurl, array(), 1.23 );
function amazin_product_box_render_in_post($productBox) {
ob_start();
$id = $productBox->ID;
$productBoxTitle = $productBox->post_title;
$stripped = stripslashes($productBox->post_content);
$content = json_decode($stripped, true);
?>
<div class="amazin-product-box" id="<?php echo 'amazin-product-box-id-'.$id; ?>" style="border:1px solid grey;">
<div class="amazin-product-box" id="<?php echo 'amazin-product-box-id-'.$id; ?>">
<p class="amazin-product-box-recommend-text">We recommend</p>
<h3 class="amazin-product-box-product-name"><?php echo $productBoxTitle ?></h3>
<p class="amazin-product-box-tagline"><?php echo $content['productTagline'] ?></p>
<p class="amazin-product-box-description" ><?php echo $content['productDescription'] ?></p>
<a class="amazin-product-box-button" href="<?php echo $content['productLink'] ?>"><?php echo $content['productButtonText'] ?></a>
<div class="row">
<div class="amazin-product-box-column amazin-product-box-left">
Picture placeholder
</div>
<div class="amazin-product-box-column amazin-product-box-right">
<p class="amazin-product-box-tagline"><?php echo $content['productTagline'] ?></p>
<p class="amazin-product-box-description" ><?php echo $content['productDescription'] ?></p>
</div>
</div>
<div class="amazin-product-box-button-wrap">
<a href="<?php echo $content['productLink'] ?>" class="amazin-product-box-button"><?php echo $content['productButtonText'] ?></a>
</div>
</div>
<?php
return ob_get_clean();
@@ -192,11 +204,11 @@ function post_new_product_box() {
$id = $_POST['amazin-product-id'];
$content = array(
"productName" => $_POST['amazin-product-name'],
"productTagline" => $_POST['amazin-product-tagline'],
"productDescription" => $_POST['amazin-product-description'],
"productUrl" => $_POST['amazin-product-url'],
"productButtonText" => $_POST['amazin-product-button-text']
'productName' => $_POST['amazin-product-name'],
'productTagline' => $_POST['amazin-product-tagline'],
'productDescription' => $_POST['amazin-product-description'],
'productUrl' => $_POST['amazin-product-url'],
'productButtonText' => $_POST['amazin-product-button-text']
);
$product_box = array(
@@ -234,10 +246,13 @@ function amazin_delete_post( ) {
function amazin_get_existing_post( ) {
$post = get_post($_REQUEST['id']);
if ($post) {
$stripped = stripslashes($post->post_content);
$content = json_decode($stripped, true);
$postDataToBePassed = array(
'productBoxProductName' => $post->post_title,
'productBoxID' => $post->ID,
'productBoxData' => $post->post_content
'productBoxData' => $content
);
wp_send_json($postDataToBePassed);
} else {
@@ -36,7 +36,7 @@ jQuery ( document ).ready ( function ( $ ) {
},
success: function ( response ) {
var id = response.productBoxID;
var data = JSON.parse(response.productBoxData);
var data = response.productBoxData;

$ ("#current-form-behavior-title").text("Editing Product Box ID " + id);

@@ -0,0 +1,60 @@
/* Default styles for the Amazin' Product Box */
.amazin-product-box {
border:1px solid grey;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
padding:28px;
}

.amazin-product-box-column {
float:left;
}

.amazin-product-box-left {
width:50%;
}

.amazin-product-box-right {
width:50%;
}

.amazin-product-box-recommend-text {
text-transform:uppercase;
font-size:.8em;
letter-spacing: 3px;
text-align:center;
margin-bottom:0px;
}

.amazin-product-box-product-name {
text-align:center;
margin:10px 0px 32px;
}

.amazin-product-box-tagline {
font-weight:bold;
margin:0px;
line-height:1.4;
}

.amazin-product-box-description {
line-height:1.4;
}

.amazin-product-box-button-wrap {
text-align:center;
}

.amazin-product-box a, .amazin-product-box a:visited {
color:white;
text-decoration:none !important;
}

.amazin-product-box-button {
background-color: #85bf31;
padding:12px 18px;
text-align:center;
display:inline-block;
border-radius:8px;
margin:10px;
font-family:sans-serif;
}

0 comments on commit f1b7c61

Please sign in to comment.
You can’t perform that action at this time.