Example #1
0
 /**
  * Finds item for specified WordPress post.
  *
  * @param $post \WP_Post WordPress post.
  * @return Product Item found.
  */
 public function findForPost($post)
 {
     if (!isset($this->objects[$post->ID])) {
         $this->objects[$post->ID] = $this->service->findForPost($post);
     }
     return $this->objects[$post->ID];
 }
Example #2
0
 /**
  * Finds item for specified WordPress post.
  *
  * @param $post \WP_Post WordPress post.
  * @return Product Item found.
  */
 public function findForPost($post)
 {
     if (!isset($this->objects[$post->ID])) {
         $cachedProduct = $this->instanceCache->getItem('product_' . $post->ID);
         if ($cachedProduct->get() instanceof Product) {
             $this->objects[$post->ID] = $cachedProduct->get();
         } else {
             $this->objects[$post->ID] = $this->service->findForPost($post);
             $cachedProduct->set($this->objects[$post->ID]);
             $this->instanceCache->save($cachedProduct);
         }
     }
     return $this->objects[$post->ID];
 }
Example #3
0
 public function getAttachments()
 {
     $post = $this->wp->getGlobalPost();
     /** @var \Jigoshop\Entity\Product $product */
     $product = $this->productService->findForPost($post);
     return $this->productService->getAttachments($product);
 }
Example #4
0
 /**
  * @param Wordpress $wp
  */
 public function addFrontendAssets(Wordpress $wp)
 {
     $post = $wp->getGlobalPost();
     $product = $this->productService->findForPost($post);
     if ($product instanceof Product\Variable) {
         $variations = array();
         foreach ($product->getVariations() as $variation) {
             /** @var $variation Product\Variable\Variation */
             $variations[$variation->getId()] = array('price' => $variation->getProduct()->getPrice(), 'html' => array('price' => \Jigoshop\Helper\Product::formatPrice($variation->getProduct()->getPrice())), 'attributes' => array());
             foreach ($variation->getAttributes() as $attribute) {
                 /** @var $attribute Product\Variable\Attribute */
                 $variations[$variation->getId()]['attributes'][$attribute->getAttribute()->getId()] = $attribute->getValue();
             }
         }
         Styles::add('jigoshop.product.variable', \JigoshopInit::getUrl() . '/assets/css/shop/product/variable.css');
         Scripts::add('jigoshop.product.variable', \JigoshopInit::getUrl() . '/assets/js/shop/product/variable.js', array('jquery'));
         Scripts::localize('jigoshop.product.variable', 'jigoshop_product_variable', array('variations' => $variations));
     }
 }
Example #5
0
 public function render()
 {
     $post = $this->wp->getGlobalPost();
     $product = $this->productService->findForPost($post);
     return Render::get('shop/product', array('product' => $product, 'messages' => $this->messages));
 }