Пример #1
0
 /**
  * Finds and fetches variation for selected product and variation ID.
  *
  * @param Product\Variable $product Parent product.
  * @param int $variationId Variation ID.
  * @return Product\Variable\Variation The variation.
  */
 public function find(Product\Variable $product, $variationId)
 {
     if (!isset($this->objects[$product->getId()])) {
         $this->objects[$product->getId()] = $this->service->find($product, $variationId);
     }
     return $this->objects[$product->getId()];
 }
Пример #2
0
 /**
  * @return string Variation title.
  */
 public function getTitle()
 {
     // TODO: Title changing description in docs
     if ($this->title === null) {
         $this->title = sprintf(_x('%s (%s)', 'product_variation', 'jigoshop'), $this->parent->getName(), join(', ', array_filter(array_map(function ($item) {
             /** @var $item Attribute */
             $value = $item->getValue();
             if (is_numeric($value) && $value > 0) {
                 return sprintf(_x('%s: %s', 'product_variation', 'jigoshop'), $item->getAttribute()->getLabel(), $item->getAttribute()->getOption($value)->getLabel());
             } else {
                 return sprintf(_x('%s: any', 'product_variation', 'jigoshop'), $item->getAttribute()->getLabel());
             }
             return '';
         }, $this->attributes))));
     }
     return $this->title;
 }
Пример #3
0
 /**
  * Get additional information about the products of variables.
  *
  * @param \Jigoshop\Entity\Product\Variable $product - Product
  * @param string $type - chose to display sku or stock information
  *
  * @return string
  */
 public function getVariableAdditionalInfo($product, $type)
 {
     if ($product->getType() == Product\Variable::TYPE && $this->options->get('advanced.products_list.variations_sku_stock')) {
         $additionalInfo = '';
         /** @var \Jigoshop\Entity\Product\Variable\Variation $variation */
         /** @var Product\Attribute $attribute */
         foreach ($product->getVariations() as $variation) {
             if ($type == 'sku') {
                 $additionalInfo .= $variation->getProduct()->getSku() . '<br />';
             } elseif ($type == 'stock') {
                 $variation_name = array();
                 $attributes = $product->getVariableAttributes();
                 foreach ($attributes as $attribute) {
                     $variation_name[] = ProductHelper::getSelectOption($attribute->getOptions())[$variation->getAttribute($attribute->getId())->getValue()];
                 }
                 $additionalInfo .= join(' - ', $variation_name) . ' (' . $variation->getProduct()->getStock()->getStock() . ')<br />';
             }
         }
         return $additionalInfo;
     } else {
         if ($type == 'sku') {
             return $product->getSku();
         } elseif ($type == 'stock') {
             return ProductHelper::getStock($product);
         }
     }
 }