modules/XC/ProductVariants/src/Model/ProductVariant.php line 98

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2001-present X-Cart Holdings LLC. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XC\ProductVariants\Model;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use XC\ProductVariants\API\Endpoint\ProductVariant\DTO\ProductVariantInput as Input;
  10. use XC\ProductVariants\API\Endpoint\ProductVariant\DTO\ProductVariantUpdate as Update;
  11. use XC\ProductVariants\API\Endpoint\ProductVariant\DTO\ProductVariantOutput as Output;
  12. use XC\ProductVariants\Controller\API\ProductVariant\Delete;
  13. use XC\ProductVariants\Controller\API\ProductVariant\Put;
  14. use XC\ProductVariants\Model\Product\ProductVariantsStockAvailabilityPolicy;
  15. use XLite\Model\Cart;
  16. /**
  17.  * Product variant
  18.  *
  19.  * @ORM\Entity
  20.  * @ORM\Table  (name="product_variants")
  21.  *
  22.  * @ApiPlatform\ApiResource(
  23.  *     shortName="Product Variant",
  24.  *     itemOperations={
  25.  *          "get"={
  26.  *              "method"="GET",
  27.  *              "path"="/products/{product_id}/variants/{id}.{_format}",
  28.  *              "identifiers"={"product_id", "id"},
  29.  *              "requirements"={"product_id"="\d+", "id"="\d+"},
  30.  *              "input"=Input::class,
  31.  *              "output"=Output::class,
  32.  *              "openapi_context"={
  33.  *                  "parameters"={
  34.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  35.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  36.  *                  }
  37.  *              }
  38.  *          },
  39.  *          "put"={
  40.  *              "method"="PUT",
  41.  *              "path"="/products/{product_id}/variants/{id}.{_format}",
  42.  *              "identifiers"={"product_id", "id"},
  43.  *              "requirements"={"product_id"="\d+", "id"="\d+"},
  44.  *              "controller"=Put::class,
  45.  *              "input"=Update::class,
  46.  *              "output"=Output::class,
  47.  *              "openapi_context"={
  48.  *                  "parameters"={
  49.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  50.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  51.  *                  }
  52.  *              }
  53.  *          },
  54.  *          "delete"={
  55.  *              "method"="DELETE",
  56.  *              "path"="/products/{product_id}/variants/{id}.{_format}",
  57.  *              "identifiers"={"product_id", "id"},
  58.  *              "requirements"={"product_id"="\d+", "id"="\d+"},
  59.  *              "controller"=Delete::class,
  60.  *              "input"=Input::class,
  61.  *              "output"=Output::class,
  62.  *              "openapi_context"={
  63.  *                  "parameters"={
  64.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  65.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  66.  *                  }
  67.  *              }
  68.  *          }
  69.  *     },
  70.  *     collectionOperations={
  71.  *          "get"={
  72.  *              "method"="GET",
  73.  *              "path"="/products/{product_id}/variants.{_format}",
  74.  *              "identifiers"={"product_id"},
  75.  *              "requirements"={"product_id"="\d+"},
  76.  *              "input"=Input::class,
  77.  *              "output"=Output::class,
  78.  *              "openapi_context"={
  79.  *                  "parameters"={
  80.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  81.  *                  },
  82.  *              }
  83.  *          },
  84.  *          "post"={
  85.  *              "method"="POST",
  86.  *              "path"="/products/{product_id}/variants.{_format}",
  87.  *              "controller"="xcart.api.xc.product_variants.product_variant.controller",
  88.  *              "identifiers"={"product_id"},
  89.  *              "requirements"={"product_id"="\d+"},
  90.  *              "input"=Input::class,
  91.  *              "output"=Output::class,
  92.  *              "openapi_context"={
  93.  *                  "parameters"={
  94.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  95.  *                  }
  96.  *              }
  97.  *          }
  98.  *     }
  99.  * )
  100.  */
  101. class ProductVariant extends \XLite\Model\AEntity
  102. {
  103.     /**
  104.      * Unique ID
  105.      *
  106.      * @var integer
  107.      *
  108.      * @ORM\Id
  109.      * @ORM\GeneratedValue (strategy="AUTO")
  110.      * @ORM\Column         (type="integer", options={ "unsigned": true })
  111.      */
  112.     protected $id;
  113.     /**
  114.      * Product
  115.      *
  116.      * @var \XLite\Model\Product
  117.      *
  118.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Product", inversedBy="variants")
  119.      * @ORM\JoinColumn (name="product_id", referencedColumnName="product_id", onDelete="CASCADE")
  120.      */
  121.     protected $product;
  122.     /**
  123.      * Price
  124.      *
  125.      * @var float
  126.      *
  127.      * @ORM\Column (type="decimal", precision=14, scale=4)
  128.      */
  129.     protected $price 0.0000;
  130.     /**
  131.      * Default price flag
  132.      *
  133.      * @var boolean
  134.      *
  135.      * @ORM\Column (type="boolean")
  136.      */
  137.     protected $defaultPrice true;
  138.     /**
  139.      * Amount
  140.      *
  141.      * @var integer
  142.      *
  143.      * @ORM\Column (type="integer", options={ "unsigned": true })
  144.      */
  145.     protected $amount 0;
  146.     /**
  147.      * Default amount flag
  148.      *
  149.      * @var boolean
  150.      *
  151.      * @ORM\Column (type="boolean")
  152.      */
  153.     protected $defaultAmount true;
  154.     /**
  155.      * Weight
  156.      *
  157.      * @var float
  158.      *
  159.      * @ORM\Column (type="decimal", precision=14, scale=4)
  160.      */
  161.     protected $weight 0.0000;
  162.     /**
  163.      * Default weight flag
  164.      *
  165.      * @var boolean
  166.      *
  167.      * @ORM\Column (type="boolean")
  168.      */
  169.     protected $defaultWeight true;
  170.     /**
  171.      * Product SKU
  172.      *
  173.      * @var string
  174.      *
  175.      * @ORM\Column (type="string", length=32, nullable=true)
  176.      */
  177.     protected $sku;
  178.     /**
  179.      * Product variant unique id
  180.      *
  181.      * @var string
  182.      *
  183.      * @ORM\Column (type="string", length=32, nullable=true)
  184.      */
  185.     protected $variant_id;
  186.     /**
  187.      * Default flag
  188.      *
  189.      * @var boolean
  190.      *
  191.      * @ORM\Column (type="boolean")
  192.      */
  193.     protected $defaultValue false;
  194.     /**
  195.      * Image
  196.      *
  197.      * @var \XC\ProductVariants\Model\Image\ProductVariant\Image
  198.      *
  199.      * @ORM\OneToOne  (targetEntity="XC\ProductVariants\Model\Image\ProductVariant\Image", mappedBy="product_variant", cascade={"all"})
  200.      */
  201.     protected $image;
  202.     /**
  203.      * Attribute value (checkbox)
  204.      *
  205.      * @var \Doctrine\Common\Collections\Collection
  206.      *
  207.      * @ORM\ManyToMany (targetEntity="XLite\Model\AttributeValue\AttributeValueCheckbox", inversedBy="variants")
  208.      * @ORM\JoinTable (
  209.      *      name="product_variant_attribute_value_checkbox",
  210.      *      joinColumns={@ORM\JoinColumn (name="variant_id", referencedColumnName="id", onDelete="CASCADE")},
  211.      *      inverseJoinColumns={@ORM\JoinColumn (name="attribute_value_id", referencedColumnName="id", onDelete="CASCADE")}
  212.      * )
  213.      */
  214.     protected $attributeValueC;
  215.     /**
  216.      * Attribute value (select)
  217.      *
  218.      * @var \Doctrine\Common\Collections\Collection
  219.      *
  220.      * @ORM\ManyToMany (targetEntity="XLite\Model\AttributeValue\AttributeValueSelect", inversedBy="variants")
  221.      * @ORM\JoinTable (
  222.      *      name="product_variant_attribute_value_select",
  223.      *      joinColumns={@ORM\JoinColumn (name="variant_id", referencedColumnName="id", onDelete="CASCADE")},
  224.      *      inverseJoinColumns={@ORM\JoinColumn (name="attribute_value_id", referencedColumnName="id", onDelete="CASCADE")}
  225.      * )
  226.      */
  227.     protected $attributeValueS;
  228.     /**
  229.      * Product order items
  230.      *
  231.      * @var \Doctrine\ORM\PersistentCollection
  232.      *
  233.      * @ORM\OneToMany (targetEntity="XLite\Model\OrderItem", mappedBy="variant")
  234.      */
  235.     protected $orderItems;
  236.     /**
  237.      * Constructor
  238.      *
  239.      * @param array $data Entity properties OPTIONAL
  240.      */
  241.     public function __construct(array $data = [])
  242.     {
  243.         $this->attributeValueC = new \Doctrine\Common\Collections\ArrayCollection();
  244.         $this->attributeValueS = new \Doctrine\Common\Collections\ArrayCollection();
  245.         $this->orderItems = new \Doctrine\Common\Collections\ArrayCollection();
  246.         parent::__construct($data);
  247.     }
  248.     /**
  249.      * Get attribute value
  250.      *
  251.      * @param \XLite\Model\Attribute $attribute Attribute
  252.      *
  253.      * @return mixed
  254.      */
  255.     public function getAttributeValue(\XLite\Model\Attribute $attribute)
  256.     {
  257.         $result null;
  258.         foreach ($this->getValues() as $v) {
  259.             if ($v->getAttribute()->getId() == $attribute->getId()) {
  260.                 $result $v;
  261.                 break;
  262.             }
  263.         }
  264.         return $result;
  265.     }
  266.     /**
  267.      * Get attribute values
  268.      *
  269.      * @return array
  270.      */
  271.     public function getValues()
  272.     {
  273.         return array_merge(
  274.             $this->getAttributeValueS()->toArray(),
  275.             $this->getAttributeValueC()->toArray()
  276.         );
  277.     }
  278.     /**
  279.      * Increase / decrease product inventory amount
  280.      *
  281.      * @param integer $delta Amount delta
  282.      */
  283.     public function changeAmount($delta)
  284.     {
  285.         if (!$this->getDefaultAmount()) {
  286.             $this->setAmount($this->getAmount() + $delta);
  287.         }
  288.     }
  289.     /**
  290.      * Get attribute values hash
  291.      *
  292.      * @return string
  293.      */
  294.     public function getValuesHash()
  295.     {
  296.         $hash = [];
  297.         foreach ($this->getValues() as $av) {
  298.             $hash[] = $av->getAttribute()->getId() . '_' $av->getId();
  299.         }
  300.         sort($hash);
  301.         return md5(implode('_'$hash));
  302.     }
  303.     /**
  304.      * Get quick data price
  305.      *
  306.      * @return float
  307.      */
  308.     public function getQuickDataPrice()
  309.     {
  310.         return $this->getClearPrice();
  311.     }
  312.     /**
  313.      * Get clear price
  314.      *
  315.      * @return float
  316.      */
  317.     public function getClearPrice()
  318.     {
  319.         return $this->getDefaultPrice()
  320.             ? $this->getProduct()->getPrice()
  321.             : $this->getPrice();
  322.     }
  323.     /**
  324.      * Get net Price
  325.      *
  326.      * @return float
  327.      */
  328.     public function getNetPrice()
  329.     {
  330.         return \XLite\Logic\Price::getInstance()->apply($this'getClearPrice', ['taxable'], 'net');
  331.     }
  332.     /**
  333.      * Get display Price
  334.      *
  335.      * @return float
  336.      */
  337.     public function getDisplayPrice()
  338.     {
  339.         return \XLite\Logic\Price::getInstance()->apply($this'getNetPrice', ['taxable'], 'display');
  340.     }
  341.     /**
  342.      * Get clear weight
  343.      *
  344.      * @return float
  345.      */
  346.     public function getClearWeight()
  347.     {
  348.         return $this->getDefaultWeight()
  349.             ? $this->getProduct()->getWeight()
  350.             : $this->getWeight();
  351.     }
  352.     /**
  353.      * Get display sku
  354.      *
  355.      * @return float
  356.      */
  357.     public function getDisplaySku()
  358.     {
  359.         return $this->getSku() ?: $this->getProduct()->getSku();
  360.     }
  361.     /**
  362.      * Get SKU
  363.      *
  364.      * @return string
  365.      */
  366.     public function getSku()
  367.     {
  368.         return $this->sku !== null ? (string)$this->sku null;
  369.     }
  370.     /**
  371.      * Set sku and trim it to max length
  372.      *
  373.      * @param string $sku
  374.      */
  375.     public function setSku($sku)
  376.     {
  377.         $this->sku substr($sku0\XLite\Core\Database::getRepo('XC\ProductVariants\Model\ProductVariant')->getFieldInfo('sku''length'));
  378.     }
  379.     /**
  380.      * Return VariantId
  381.      *
  382.         @return string
  383.      */
  384.     public function getVariantId()
  385.     {
  386.         return $this->variant_id;
  387.     }
  388.     /**
  389.      * Set VariantId
  390.      *
  391.      * @param string $variant_id
  392.      *
  393.      * @return $this
  394.      */
  395.     public function setVariantId($variant_id)
  396.     {
  397.         $this->variant_id $variant_id;
  398.         return $this;
  399.     }
  400.     /**
  401.      * Set needProcess to related product
  402.      *
  403.      * @param boolean $needProcess
  404.      *
  405.      * @return \XLite\Model\Product
  406.      */
  407.     public function setNeedProcess($needProcess)
  408.     {
  409.         if ($this->getProduct()) {
  410.             $this->getProduct()->setNeedProcess($needProcess);
  411.         }
  412.         return $this->getProduct();
  413.     }
  414.     /**
  415.      * Check if the product is out-of-stock
  416.      *
  417.      * @return boolean
  418.      */
  419.     public function isShowStockWarning()
  420.     {
  421.         return $this->getProduct()
  422.             && $this->getProduct()->getInventoryEnabled()
  423.             && $this->getProduct()->getLowLimitEnabledCustomer()
  424.             && ($this->getPublicAmount() <= $this->getProduct()->getLowLimitAmount())
  425.             && !$this->isOutOfStock();
  426.     }
  427.     /**
  428.      * Return true if product variant can be purchased
  429.      *
  430.      * @return boolean
  431.      */
  432.     public function isAvailable()
  433.     {
  434.         return $this->availableInDate()
  435.             && !$this->isOutOfStock();
  436.     }
  437.     /**
  438.      * Flag if the product is available according date/time
  439.      *
  440.      * @return boolean
  441.      */
  442.     public function availableInDate()
  443.     {
  444.         return $this->getProduct()
  445.             ? $this->getProduct()->availableInDate()
  446.             : true;
  447.     }
  448.     /**
  449.      * Alias: is product in stock or not
  450.      *
  451.      * @return boolean
  452.      */
  453.     public function isOutOfStock()
  454.     {
  455.         /** @var ProductVariantsStockAvailabilityPolicy $availabilityPolicy */
  456.         $availabilityPolicy $this->getProduct()->getStockAvailabilityPolicy();
  457.         return !$availabilityPolicy->getAvailableVariantAmount(Cart::getInstance(), $this->getId());
  458.     }
  459.     /**
  460.      * Return public amount
  461.      *
  462.      * @return integer
  463.      */
  464.     public function getPublicAmount()
  465.     {
  466.         return $this->getDefaultAmount()
  467.             ? $this->getProduct()->getPublicAmount()
  468.             : $this->getAmount();
  469.     }
  470.     /**
  471.      * Return product amount available to add to cart
  472.      *
  473.      * @return integer
  474.      */
  475.     public function getAvailableAmount()
  476.     {
  477.         /** @var ProductVariantsStockAvailabilityPolicy $availabilityPolicy */
  478.         $availabilityPolicy $this->getProduct()->getStockAvailabilityPolicy();
  479.         return $availabilityPolicy->getAvailableVariantAmount(Cart::getInstance(), $this->getId());
  480.     }
  481.     /**
  482.      * Return max possibly product amount available to add to cart
  483.      *
  484.      * @return integer
  485.      */
  486.     public function getMaxAmount()
  487.     {
  488.         return $this->getAvailableAmount();
  489.     }
  490.     /**
  491.      * How many product items added to cart
  492.      *
  493.      * @return boolean
  494.      */
  495.     public function getItemsInCart()
  496.     {
  497.         $availabilityPolicy $this->getProduct()->getStockAvailabilityPolicy();
  498.         return $availabilityPolicy->getInCartVariantAmount(Cart::getInstance(), $this->getId());
  499.     }
  500.     /**
  501.      * How many product items added to cart
  502.      *
  503.      * @return boolean
  504.      */
  505.     public function getItemsInCartMessage()
  506.     {
  507.         $availabilityPolicy $this->getProduct()->getStockAvailabilityPolicy();
  508.         $count $availabilityPolicy->getInCartVariantAmount(Cart::getInstance(), $this->getId());
  509.         return \XLite\Core\Translation::getInstance()->translate(
  510.             'Items with selected options in your cart: X',
  511.             ['count' => $count]
  512.         );
  513.     }
  514.     /**
  515.      * Alias: is all product items in cart
  516.      *
  517.      * @return boolean
  518.      */
  519.     public function isAllStockInCart()
  520.     {
  521.         return $this->getAvailableAmount() <= $this->getItemsInCart();
  522.     }
  523.     /**
  524.      * Clone
  525.      *
  526.      * @return \XLite\Model\AEntity
  527.      */
  528.     public function cloneEntity()
  529.     {
  530.         $newEntity parent::cloneEntity();
  531.         if ($this->getSku()) {
  532.             $newEntity->setSku(
  533.                 \XLite\Core\Database::getRepo('XC\ProductVariants\Model\ProductVariant')
  534.                     ->assembleUniqueSKU($this->getSku())
  535.             );
  536.         }
  537.         $newEntity->setVariantId(
  538.             \XLite\Core\Database::getRepo('XC\ProductVariants\Model\ProductVariant')
  539.                     ->assembleUniqueVariantId($this->getVariantId())
  540.         );
  541.         $this->cloneEntityImage($newEntity);
  542.         return $newEntity;
  543.     }
  544.     /**
  545.      * Clone entity (image)
  546.      *
  547.      * @param \XC\ProductVariants\Model\ProductVariant $newEntity New entity
  548.      */
  549.     public function cloneEntityImage(\XC\ProductVariants\Model\ProductVariant $newEntity)
  550.     {
  551.         if ($this->getImage()) {
  552.             $newImage $this->getImage()->cloneEntity();
  553.             $newImage->setProductVariant($newEntity);
  554.             $newEntity->setImage($newImage);
  555.         }
  556.     }
  557.     /**
  558.      * Return taxable
  559.      *
  560.      * @return boolean
  561.      */
  562.     public function getTaxable()
  563.     {
  564.         return $this->getProduct()->getTaxable();
  565.     }
  566.     /**
  567.      * Check if product amount is less than its low limit
  568.      *
  569.      * @return boolean
  570.      */
  571.     public function isLowLimitReached()
  572.     {
  573.         /** @var \XLite\Model\Product $product */
  574.         $product $this->getProduct();
  575.         return $product->getLowLimitEnabled() && $this->getPublicAmount() <= $product->getLowLimitAmount();
  576.     }
  577.     /**
  578.      * List of controllers which should not send notifications
  579.      *
  580.      * @return array
  581.      */
  582.     protected function getForbiddenControllers()
  583.     {
  584.         return [
  585.             '\XLite\Controller\Admin\EventTask',
  586.             '\XLite\Controller\Admin\ProductList',
  587.             '\XLite\Controller\Admin\Product',
  588.         ];
  589.     }
  590.     /**
  591.      * Check if notifications should be sent in current situation
  592.      *
  593.      * @return boolean
  594.      */
  595.     public function isShouldSend()
  596.     {
  597.         $currentController \XLite::getInstance()->getController();
  598.         $isControllerForbidden array_reduce(
  599.             $this->getForbiddenControllers(),
  600.             static function ($carry$controllerName) use ($currentController) {
  601.                 return $carry ?: ($currentController instanceof $controllerName);
  602.             },
  603.             false
  604.         );
  605.         return
  606.             \XLite\Core\Request::getInstance()->event !== 'import'
  607.             && !$isControllerForbidden;
  608.     }
  609.     /**
  610.      * Send notification to admin about product low limit
  611.      */
  612.     public function sendLowLimitNotification()
  613.     {
  614.         \XLite\Core\Mailer::sendLowVariantLimitWarningAdmin(
  615.             $this->prepareDataForNotification()
  616.         );
  617.     }
  618.     /**
  619.      * Prepare data for 'low limit warning' email notifications
  620.      *
  621.      * @return array
  622.      */
  623.     public function prepareDataForNotification()
  624.     {
  625.         $data = [];
  626.         $product $this->getProduct();
  627.         $data['product'] = $product;
  628.         $data['name'] = $product->getName();
  629.         $data['attributes'] = $this->prepareAttributesForEmail();
  630.         $data['sku'] = $this->getDisplaySku();
  631.         $data['amount'] = $this->getAmount();
  632.         $data['variantsTabUrl'] = $this->getUrlToVariant();
  633.         return $data;
  634.     }
  635.     /**
  636.      * Prepare attributes for view
  637.      *
  638.      * @return array
  639.      */
  640.     protected function prepareAttributesForEmail()
  641.     {
  642.         $attrs = [];
  643.         foreach ($this->getValues() as $attributeValue) {
  644.             if ($attributeValue->getAttribute()->isVariable($this->getProduct())) {
  645.                 $attrs[] = [
  646.                     'name'  => $attributeValue->getAttribute()->getName(),
  647.                     'value' => $attributeValue->asString(),
  648.                 ];
  649.             }
  650.         }
  651.         return $attrs;
  652.     }
  653.     /**
  654.      * Get url to variants tab
  655.      *
  656.      * @return string
  657.      */
  658.     protected function getUrlToVariant()
  659.     {
  660.         $params = [
  661.             'product_id' => $this->getProduct()->getProductId(),
  662.             'page'       => 'variants',
  663.         ];
  664.         $fullUrl \XLite\Core\Converter::buildFullURL(
  665.             'product',
  666.             '',
  667.             $params,
  668.             \XLite::getAdminScript()
  669.         );
  670.         $hashForUrl sprintf('#data-%d-amount'$this->getId());
  671.         return $fullUrl $hashForUrl;
  672.     }
  673.     /**
  674.      * Get id
  675.      *
  676.      * @return integer
  677.      */
  678.     public function getId()
  679.     {
  680.         return $this->id;
  681.     }
  682.     /**
  683.      * Set price
  684.      *
  685.      * @param float $price
  686.      * @return ProductVariant
  687.      */
  688.     public function setPrice($price)
  689.     {
  690.         $this->price $price;
  691.         return $this;
  692.     }
  693.     /**
  694.      * Get price
  695.      *
  696.      * @return float
  697.      */
  698.     public function getPrice()
  699.     {
  700.         return $this->price;
  701.     }
  702.     /**
  703.      * Set defaultPrice
  704.      *
  705.      * @param boolean $defaultPrice
  706.      * @return ProductVariant
  707.      */
  708.     public function setDefaultPrice($defaultPrice)
  709.     {
  710.         $this->defaultPrice $defaultPrice;
  711.         return $this;
  712.     }
  713.     /**
  714.      * Get defaultPrice
  715.      *
  716.      * @return boolean
  717.      */
  718.     public function getDefaultPrice()
  719.     {
  720.         return $this->defaultPrice;
  721.     }
  722.     /**
  723.      * Set amount
  724.      *
  725.      * @param integer $amount
  726.      * @return ProductVariant
  727.      */
  728.     public function setAmount($amount)
  729.     {
  730.         $this->amount $this->correctAmount($amount);
  731.         return $this;
  732.     }
  733.     /**
  734.      * Get amount
  735.      *
  736.      * @return integer
  737.      */
  738.     public function getAmount()
  739.     {
  740.         return $this->amount;
  741.     }
  742.     /**
  743.      * Set defaultAmount
  744.      *
  745.      * @param boolean $defaultAmount
  746.      * @return ProductVariant
  747.      */
  748.     public function setDefaultAmount($defaultAmount)
  749.     {
  750.         $this->defaultAmount $defaultAmount;
  751.         return $this;
  752.     }
  753.     /**
  754.      * Get defaultAmount
  755.      *
  756.      * @return boolean
  757.      */
  758.     public function getDefaultAmount()
  759.     {
  760.         return $this->defaultAmount;
  761.     }
  762.     /**
  763.      * Set weight
  764.      *
  765.      * @param float $weight
  766.      * @return ProductVariant
  767.      */
  768.     public function setWeight($weight)
  769.     {
  770.         $this->weight $weight;
  771.         return $this;
  772.     }
  773.     /**
  774.      * Get weight
  775.      *
  776.      * @return float
  777.      */
  778.     public function getWeight()
  779.     {
  780.         return $this->weight;
  781.     }
  782.     /**
  783.      * Set defaultWeight
  784.      *
  785.      * @param boolean $defaultWeight
  786.      * @return ProductVariant
  787.      */
  788.     public function setDefaultWeight($defaultWeight)
  789.     {
  790.         $this->defaultWeight $defaultWeight;
  791.         return $this;
  792.     }
  793.     /**
  794.      * Get defaultWeight
  795.      *
  796.      * @return boolean
  797.      */
  798.     public function getDefaultWeight()
  799.     {
  800.         return $this->defaultWeight;
  801.     }
  802.     /**
  803.      * Set defaultValue
  804.      *
  805.      * @param boolean $defaultValue
  806.      * @return ProductVariant
  807.      */
  808.     public function setDefaultValue($defaultValue)
  809.     {
  810.         $this->defaultValue $defaultValue;
  811.         return $this;
  812.     }
  813.     /**
  814.      * Get defaultValue
  815.      *
  816.      * @return boolean
  817.      */
  818.     public function getDefaultValue()
  819.     {
  820.         return $this->defaultValue;
  821.     }
  822.     /**
  823.      * Set product
  824.      *
  825.      * @param \XLite\Model\Product $product
  826.      * @return ProductVariant
  827.      */
  828.     public function setProduct(\XLite\Model\Product $product null)
  829.     {
  830.         $this->product $product;
  831.         return $this;
  832.     }
  833.     /**
  834.      * Get product
  835.      *
  836.      * @return \XLite\Model\Product
  837.      */
  838.     public function getProduct()
  839.     {
  840.         return $this->product;
  841.     }
  842.     /**
  843.      * Set image
  844.      *
  845.      * @param \XC\ProductVariants\Model\Image\ProductVariant\Image $image
  846.      * @return ProductVariant
  847.      */
  848.     public function setImage(\XC\ProductVariants\Model\Image\ProductVariant\Image $image null)
  849.     {
  850.         $this->image $image;
  851.         return $this;
  852.     }
  853.     /**
  854.      * Get image
  855.      *
  856.      * @return \XC\ProductVariants\Model\Image\ProductVariant\Image
  857.      */
  858.     public function getImage()
  859.     {
  860.         return $this->image;
  861.     }
  862.     /**
  863.      * Add attributeValueC
  864.      *
  865.      * @param \XLite\Model\AttributeValue\AttributeValueCheckbox $attributeValueC
  866.      * @return ProductVariant
  867.      */
  868.     public function addAttributeValueC(\XLite\Model\AttributeValue\AttributeValueCheckbox $attributeValueC)
  869.     {
  870.         $this->attributeValueC[] = $attributeValueC;
  871.         return $this;
  872.     }
  873.     /**
  874.      * Get attributeValueC
  875.      *
  876.      * @return \Doctrine\Common\Collections\Collection
  877.      */
  878.     public function getAttributeValueC()
  879.     {
  880.         return $this->attributeValueC;
  881.     }
  882.     /**
  883.      * Add attributeValueS
  884.      *
  885.      * @param \XLite\Model\AttributeValue\AttributeValueSelect $attributeValueS
  886.      * @return ProductVariant
  887.      */
  888.     public function addAttributeValueS(\XLite\Model\AttributeValue\AttributeValueSelect $attributeValueS)
  889.     {
  890.         $this->attributeValueS[] = $attributeValueS;
  891.         return $this;
  892.     }
  893.     /**
  894.      * Get attributeValueS
  895.      *
  896.      * @return \Doctrine\Common\Collections\Collection
  897.      */
  898.     public function getAttributeValueS()
  899.     {
  900.         return $this->attributeValueS;
  901.     }
  902.     /**
  903.      * Add orderItems
  904.      *
  905.      * @param \XLite\Model\OrderItem $orderItems
  906.      * @return ProductVariant
  907.      */
  908.     public function addOrderItems(\XLite\Model\OrderItem $orderItems)
  909.     {
  910.         $this->orderItems[] = $orderItems;
  911.         return $this;
  912.     }
  913.     /**
  914.      * Get orderItems
  915.      *
  916.      * @return \Doctrine\Common\Collections\Collection
  917.      */
  918.     public function getOrderItems()
  919.     {
  920.         return $this->orderItems;
  921.     }
  922.     /**
  923.      * Check and (if needed) correct amount value
  924.      *
  925.      * @param integer $amount Value to check
  926.      *
  927.      * @return integer
  928.      */
  929.     protected function correctAmount($amount)
  930.     {
  931.         return max(0, (int) $amount);
  932.     }
  933. }