Overview

Namespaces

  • Apptus
    • ESales
      • Connector
        • Report
        • Time
    • Util
      • Cache
  • PHP
  • Overview
  • Namespace
  • Class
  • Tree
  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:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 
<?php
namespace Apptus\ESales\Connector;

/**
 * Represents a product variant.
 */
class Variant implements \IteratorAggregate {
    private $ticket;
    private $attributes;
    private $categoryReferenceAttributes;

    /**
     * @internal
     * @param string|null $ticket
     * @param array $attributes
     * @param array $categoryReferenceAttributes
     */
    public function __construct($ticket = null, array $attributes = array(), array $categoryReferenceAttributes = array())
    {
        $this->ticket = $ticket;
        $this->attributes = $attributes;
        $this->categoryReferenceAttributes = $categoryReferenceAttributes;
    }

    /**
     * Get the attribute with the specified name or null if no such attribute exists for this variant.
     *
     * @param string $name
     *            The name of the attribute to get.
     * @return Attribute
     *            The attribute with the specified name or null.
     */
    public function getAttribute($name) {
        if (isset($this->attributes[$name])) {
            return $this->attributes[$name];
        }
        return null;
    }

    /**
     * Return the key of this variant.
     *
     * @return string
     *            The key of this variant.
     */
    public function key() {
        return $this->getValue('variant_key');
    }

    /**
     * Get the value of the attribute with the specified $attributeName. The specified $defaultValue
     * will be returned if no such attribute exists (defaults to null).
     *
     * @param string $attributeName
     *            The name of the attribute whose value to retrieve.
     * @param mixed $defaultValue
     *            The value to return if this variant doesn't have an attribute with the specified $attributeName.
     *            Defaults to null.
     * @return string|mixed
     *            The attribute value of attribute with the specified $attributeName, or the supplied $defaultValue
     *            if this variant has no attribute matching the name.
     */
    public function getValue($attributeName, $defaultValue = null) {
        $a = $this->getAttribute($attributeName);
        return $a === null ? $defaultValue : $a->getValue();
    }

    /**
     * Get the notification ticket of this variant.
     *
     * @return string
     *            The ticket.
     */
    public function getTicket() {
        return $this->ticket;
    }

    public function getIterator() {
        return new \ArrayIterator($this->attributes);
    }

    /**
     * Get the available category reference attributes in the variant.
     *
     * @return array The available category reference attributes in the variant as an array
     */
    public function getCategoryReferenceAttributes()
    {
        return array_keys($this->categoryReferenceAttributes);
    }

    /**
     * Get the Category objects of the given category reference attribute.
     *
     * @param string $categoryReferenceAttribute The category reference attribute to get the categories for
     * @return array The Category objects of the categoryReferenceAttribute as an array
     */
    public function getCategories($categoryReferenceAttribute)
    {
        if (isset($this->categoryReferenceAttributes[$categoryReferenceAttribute])) {
            return $this->categoryReferenceAttributes[$categoryReferenceAttribute];
        } else {
            return array();
        }
    }

    public function __toString() {
        if (isset($this->attributes['variant_key'])) {
            return (string) $this->attributes['variant_key'];
        }
        return (string) $this->attributes;
    }
}
Apptus ESales Connector PHP API documentation generated by ApiGen