/** * (PHP 5 >= 5.1.0)<br/> * String representation of object * * @link http://php.net/manual/en/serializable.serialize.php * @return string the string representation of the object or null */ public function serialize() { return serialize(array('id' => $this->id, 'key' => $this->key, 'name' => $this->name, 'type' => $this->type, 'quantity' => $this->quantity, 'price' => $this->price, 'tax' => $this->tax, 'tax_classes' => serialize($this->taxClasses), 'product_id' => $this->product->getId(), 'product' => $this->product->getState(), 'meta' => serialize($this->meta))); }
/** * @param \Jigoshop\Entity\Product $product Product to find attachments for. * @param string $size Size for images. * * @return array List of Attachments attached to the product. */ public function getAttachments(Product $product, $size = Options::IMAGE_THUMBNAIL) { $this->wp->wpUploadDir(); $uploadUrl = $this->wp->wpUploadDir()['baseurl']; $wpdb = $this->wp->getWPDB(); $attachments = $this->wp->applyFilters('jigoshop\\service\\product\\attachments\\types', array('gallery' => array(), 'downloads' => array())); $query = $wpdb->prepare("SELECT post.ID as id, post.post_title as title, post.guid as url, meta.meta_value as meta, attachment.type\n\t\t\t\tFROM {$wpdb->prefix}jigoshop_product_attachment as attachment\n\t\t\t\tLEFT JOIN {$wpdb->posts} as post ON (attachment.attachment_id = post.ID)\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} as meta ON (meta.meta_key = '_wp_attachment_metadata' AND meta.post_id = post.ID)\n\t\t\t\tWHERE product_id = %d", $product->getId()); $results = $wpdb->get_results($query, ARRAY_A); foreach ($results as $attachment) { $attachment['meta'] = unserialize($attachment['meta']); if (isset($attachment['meta']['sizes']) && isset($attachment['meta']['sizes'][$size])) { $thumbUrl = $uploadUrl . '/' . str_replace(basename($attachment['meta']['file']), basename($attachment['meta']['sizes'][$size]['file']), $attachment['meta']['file']); } else { $thumbUrl = $uploadUrl . '/' . $attachment['meta']['file']; } $attachments[$attachment['type']][] = array('id' => $attachment['id'], 'title' => $attachment['title'], 'url' => isset($attachment['meta']['file']) ? $uploadUrl . '/' . $attachment['meta']['file'] : $attachment['url'], 'thumbnail' => $thumbUrl, 'image' => $this->wp->wpGetAttachmentImage($attachment['id'], $size)); } return $attachments; }
/** * @param Product $product Product to find attachments for. * @param string $size Size for images. * @return array List of attachments attached to the product. */ public function getAttachments(Product $product, $size = Options::IMAGE_THUMBNAIL) { if (!isset($this->attachments[$product->getId()])) { $this->attachments[$product->getId()] = $this->service->getAttachments($product, $size); } return $this->attachments[$product->getId()]; }
public static function getRelated(Entity\Product $product, $limit = 5) { $cats = array_map(function ($category) { return $category['id']; }, $product->getCategories()); $tags = array_map(function ($tag) { return $tag['id']; }, $product->getTags()); // Only get related posts that are in stock & visible $query = array('posts_per_page' => $limit, 'post__not_in' => array($product->getId()), 'post_type' => Types::PRODUCT, 'orderby' => 'rand', 'meta_query' => array(array('key' => 'visibility', 'value' => array(Entity\Product::VISIBILITY_CATALOG, Entity\Product::VISIBILITY_PUBLIC), 'compare' => 'IN')), 'tax_query' => array('relation' => 'OR')); if (!empty($cats)) { $query['tax_query'][] = array('taxonomy' => Types::PRODUCT_CATEGORY, 'terms' => $cats, 'operator' => 'IN'); } if (!empty($tags)) { $query['tax_query'][] = array('taxonomy' => Types::PRODUCT_TAG, 'terms' => $tags, 'operator' => 'IN'); } return new \WP_Query($query); }