Example #1
0
 /**
  * (PHP 5 &gt;= 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)));
 }
Example #2
0
 /**
  * @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()];
 }
Example #3
0
 /**
  * Marks values provided in the state as dirty.
  *
  * @param array $state Product state.
  */
 public function markAsDirty(array $state)
 {
     $this->dirtyFields[] = 'sales';
     parent::markAsDirty($state);
 }
Example #4
0
 /**
  * @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;
 }
Example #5
0
 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);
 }
Example #6
0
 /**
  * @param Product\Attribute $attribute
  * @param Product           $product
  */
 public function addAttributes($attribute, $product)
 {
     if ($attribute instanceof Product\Attribute\Variable && $product instanceof Product\Variable) {
         /** @var $attribute Product\Attribute|Product\Attribute\Variable */
         /** @var $product Product|Product\Variable */
         if (isset($_POST['options']) && isset($_POST['options']['is_variable'])) {
             $attribute->setVariable($_POST['options']['is_variable'] === 'true');
         }
         if ($attribute->isVariable()) {
             foreach ($product->getVariations() as $variation) {
                 /** @var $variation VariableProduct\Variation */
                 if (!$variation->hasAttribute($attribute->getId())) {
                     $variableAttribute = new VariableProduct\Attribute();
                     $variableAttribute->setAttribute($attribute);
                     $variableAttribute->setVariation($variation);
                     $variation->addAttribute($variableAttribute);
                 }
             }
         }
     }
 }