-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-helpers.php
68 lines (46 loc) · 2.56 KB
/
class-helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
class jck_mwi_helpers {
/** =============================
*
* Get all required data for a product layout
*
* @product_model obj Magento product model
* @args array WP shortcode atts
* @return array
*
============================= */
public function get_product_data( $product_model, $args ) {
$product_block = new Mage_Catalog_Block_Product;
$product_data = array();
$product_data['name'] = trim($product_model->getName());
$product_data['url'] = $product_model->getProductUrl();
$product_data['images'] = false;
$product_data['description'] = false;
$product_data['price'] = false;
$product_data['add_url'] = false;
$product_data['saleable'] = $product_model->isSaleable();
$product_data['in_stock'] = $product_model->getIsInStock();
if( $args['img'] ) {
$product_data['images'] = array(
'thumb1x' => Mage::helper('catalog/image')->init($product_model, 'thumbnail')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize((int)$args['img_width'])->__toString(),
'thumb2x' => Mage::helper('catalog/image')->init($product_model, 'thumbnail')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize((int)$args['img_width']*2)->__toString()
);
}
if( $args['desc'] ) {
// get and trim description
$desc = trim($product_model->getShortDescription());
// remove first and last p tags
$desc = preg_replace('/<p[^>]*>(.*)<\/p[^>]*>/i', '$1', $desc);
// replace p tags with br br
$desc = str_replace(array('<p>','</p>'), array('','<br /><br />'), $desc);
$product_data['description'] = $desc;
}
if( $args['price'] ) {
$product_data['price'] = preg_replace( '/\s+/', ' ', $product_block->getPriceHtml($product_model, true));
}
if( $args['type'] == "add" ) {
$product_data['add_url'] = Mage::helper('checkout/cart')->getAddUrl($product_model);
}
return $product_data;
}
}