modules/CSI/MakeAnOffer/src/Model/MakeAnOffer.php line 29

Open in your IDE?
  1. <?php
  2. /* vim: set ts=4 sw=4 sts=4 et: */
  3. /**
  4.  * Make an Offer Module
  5.  *
  6.  * @category  X-Cart_5_5_Module
  7.  * @package   MakeAnOffer
  8.  * @author    CFL Systems, Inc. <support@cflsystems.com>
  9.  * @copyright 2023 CFL Systems, Inc. All rights reserved.
  10.  * @license   License Agreement - https://www.cflsystems.com/software-license-agreement.html
  11.  * @link      https://www.cflsystems.com/make-an-offer-for-x-cart-5.html
  12. */
  13. namespace CSI\MakeAnOffer\Model;
  14. use XLite\Core\Converter;
  15. use XLite\Logic\Price;
  16. use XLite\Model\Product;
  17. use XLite\Model\Profile;
  18. use Doctrine\ORM\Mapping as ORM;
  19. /**
  20.  * The "MakeAnOffer" model class
  21.  *
  22.  * @ORM\Entity
  23.  * @ORM\Table  (name="csi_make_an_offer")
  24.  */
  25. class MakeAnOffer extends \XLite\Model\AEntity
  26. {
  27.     /**
  28.      * Entry unique ID
  29.      *
  30.      * @var integer
  31.      *
  32.      * @ORM\Id
  33.      * @ORM\GeneratedValue (strategy="AUTO")
  34.      * @ORM\Column         (type="integer")
  35.      */
  36.     protected $id;
  37.     /**
  38.      * The product id request applies to
  39.      *
  40.      * @var Product
  41.      *
  42.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Product", inversedBy="makeAnOffer")
  43.      * @ORM\JoinColumn (name="product_id", referencedColumnName="product_id", onDelete="SET NULL")
  44.      */
  45.     protected $product;
  46.     /**
  47.      * The profile id request applies to
  48.      *
  49.      * @var Profile
  50.      *
  51.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Profile", inversedBy="makeAnOffer")
  52.      * @ORM\JoinColumn (name="profile_id", referencedColumnName="profile_id", onDelete="SET NULL")
  53.      */
  54.     protected $profile;
  55.     /**
  56.      * Customer name
  57.      *
  58.      * @var string
  59.      *
  60.      * @ORM\Column (type="string", length=32)
  61.      */
  62.     protected $name;
  63.     /**
  64.      * Customer email
  65.      *
  66.      * @var string
  67.      *
  68.      * @ORM\Column (type="string", length=128)
  69.      */
  70.     protected $email;
  71.     /**
  72.      * Customer phone
  73.      *
  74.      * @var string
  75.      *
  76.      * @ORM\Column (type="string", length=32)
  77.      */
  78.     protected $phone;
  79.     /**
  80.      * Product name
  81.      *
  82.      * @var string
  83.      *
  84.      * @ORM\Column (type="string", length=255)
  85.      */
  86.     protected $product_name;
  87.     /**
  88.      * Product price
  89.      *
  90.      * @var float
  91.      *
  92.      * @ORM\Column (type="decimal", precision=14, scale=4)
  93.      */
  94.     protected $product_price 0.0000;
  95.     /**
  96.      * Offer quantity
  97.      *
  98.      * @var integer
  99.      *
  100.      * @ORM\Column (type="integer")
  101.      */
  102.     protected $offer_qty 1;
  103.     /**
  104.      * Offer price
  105.      *
  106.      * @var float
  107.      *
  108.      * @ORM\Column (type="decimal", precision=14, scale=4)
  109.      */
  110.     protected $offer_price 0.0000;
  111.     /**
  112.      * Remote ip2long
  113.      *
  114.      * @var integer
  115.      *
  116.      * @ORM\Column (type="bigint")
  117.      */
  118.     protected $ip 0;
  119.     /**
  120.      * Request date
  121.      *
  122.      * @var integer
  123.      *
  124.      * @ORM\Column (type="integer")
  125.      */
  126.     protected $date 0;
  127.     /**
  128.      * Status
  129.      * A - Accepted
  130.      * D - Declined
  131.      * P - Pending
  132.      *
  133.      * @var string
  134.      *
  135.      * @ORM\Column (type="string", length=1)
  136.      */
  137.     protected $status 'P';
  138.     /**
  139.      * Admin notes (not visible to customer)
  140.      *
  141.      * @var text
  142.      *
  143.      * @ORM\Column (type="text")
  144.      */
  145.     protected $admin_notes '';
  146.     /**
  147.      * Admin notes (included in email to customer)
  148.      *
  149.      * @var text
  150.      *
  151.      * @ORM\Column (type="text")
  152.      */
  153.     protected $admin_notes_cust '';
  154.     /**
  155.      * Customer notes
  156.      *
  157.      * @var text
  158.      *
  159.      * @ORM\Column (type="text")
  160.      */
  161.     protected $customer_notes '';
  162.     /**
  163.      * Prepare date
  164.      *
  165.      * @return void
  166.      *
  167.      * @ORM\PrePersist
  168.      */
  169.     public function prepareBeforeCreate()
  170.     {
  171.         if (!$this->getDate()) {
  172.             $this->setDate(Converter::time());
  173.         }
  174.     }
  175.     /**
  176.      * Map data to entity columns
  177.      *
  178.      * @param array $data Array of data
  179.      *
  180.      * @return self
  181.      */
  182.     public function map(array $data)
  183.     {
  184.         $offer = [];
  185.         foreach ($data as $key => $value) {
  186.             if ($this->isPropertyExists($key)) {
  187.                 $offer[$key] = $value;
  188.             }
  189.         }
  190.         return parent::map($offer);
  191.     }
  192.     /**
  193.      * Get id
  194.      *
  195.      * @return integer
  196.      */
  197.     public function getId()
  198.     {
  199.         return $this->id;
  200.     }
  201.     /**
  202.      * Set name
  203.      *
  204.      * @param string $name
  205.      *
  206.      * @return self
  207.      */
  208.     public function setName($name)
  209.     {
  210.         $this->name $name;
  211.         return $this;
  212.     }
  213.     /**
  214.      * Get name
  215.      *
  216.      * @return string
  217.      */
  218.     public function getName()
  219.     {
  220.         return $this->name;
  221.     }
  222.     /**
  223.      * Set email
  224.      *
  225.      * @param string $email
  226.      *
  227.      * @return self
  228.      */
  229.     public function setEmail($email)
  230.     {
  231.         $this->email $email;
  232.         return $this;
  233.     }
  234.     /**
  235.      * Get email
  236.      *
  237.      * @return string
  238.      */
  239.     public function getEmail()
  240.     {
  241.         return $this->email;
  242.     }
  243.     /**
  244.      * Set phone
  245.      *
  246.      * @param string $phone
  247.      *
  248.      * @return self
  249.      */
  250.     public function setPhone($phone)
  251.     {
  252.         $this->phone $phone;
  253.         return $this;
  254.     }
  255.     /**
  256.      * Get phone
  257.      *
  258.      * @return string
  259.      */
  260.     public function getPhone()
  261.     {
  262.         return $this->phone;
  263.     }
  264.     /**
  265.      * Set product_name
  266.      *
  267.      * @param string $productName
  268.      *
  269.      * @return self
  270.      */
  271.     public function setProductName($productName)
  272.     {
  273.         $this->product_name $productName;
  274.         return $this;
  275.     }
  276.     /**
  277.      * Get product_name
  278.      *
  279.      * @return string
  280.      */
  281.     public function getProductName()
  282.     {
  283.         return $this->product_name;
  284.     }
  285.     /**
  286.      * Set product_price
  287.      *
  288.      * @param float $productPrice
  289.      *
  290.      * @return self
  291.      */
  292.     public function setProductPrice($productPrice)
  293.     {
  294.         $this->product_price = (float) $productPrice;
  295.         return $this;
  296.     }
  297.     /**
  298.      * Get product_price
  299.      *
  300.      * @return float
  301.      */
  302.     public function getProductPrice()
  303.     {
  304.         return $this->product_price;
  305.     }
  306.     /**
  307.      * Set offer_qty
  308.      *
  309.      * @param integer $offerQty
  310.      *
  311.      * @return self
  312.      */
  313.     public function setOfferQty($offerQty)
  314.     {
  315.         $this->offer_qty = (int) $offerQty;
  316.         return $this;
  317.     }
  318.     /**
  319.      * Get offer_qty
  320.      *
  321.      * @return integer
  322.      */
  323.     public function getOfferQty()
  324.     {
  325.         return $this->offer_qty;
  326.     }
  327.     /**
  328.      * Set offer_price
  329.      *
  330.      * @param float $offerPrice
  331.      *
  332.      * @return self
  333.      */
  334.     public function setOfferPrice($offerPrice)
  335.     {
  336.         $this->offer_price = (float) $offerPrice;
  337.         return $this;
  338.     }
  339.     /**
  340.      * Get offer_price
  341.      *
  342.      * @return float
  343.      */
  344.     public function getOfferPrice()
  345.     {
  346.         return $this->offer_price;
  347.     }
  348.     /**
  349.      * Set ip
  350.      *
  351.      * @param string $ip
  352.      *
  353.      * @return self
  354.      */
  355.     public function setIp($ip)
  356.     {
  357.         $ip ip2long($ip);
  358.         if ($ip == -|| $ip === false) {
  359.             $ip 0;
  360.         }
  361.         $this->ip $ip;
  362.         return $this;
  363.     }
  364.     /**
  365.      * Get ip
  366.      *
  367.      * @return bigint
  368.      */
  369.     public function getIp()
  370.     {
  371.         $ip long2ip($this->ip);
  372.         return empty($ip) ? $ip;
  373.     }
  374.     /**
  375.      * Set date
  376.      *
  377.      * @param integer $date
  378.      *
  379.      * @return self
  380.      */
  381.     public function setDate($date)
  382.     {
  383.         $this->date = (int) $date;
  384.         return $this;
  385.     }
  386.     /**
  387.      * Get date
  388.      *
  389.      * @return integer
  390.      */
  391.     public function getDate()
  392.     {
  393.         return $this->date;
  394.     }
  395.     /**
  396.      * Set status
  397.      *
  398.      * @param string $status
  399.      *
  400.      * @return self
  401.      */
  402.     public function setStatus($status)
  403.     {
  404.         $this->status $status;
  405.         return $this;
  406.     }
  407.     /**
  408.      * Get status
  409.      *
  410.      * @return string
  411.      */
  412.     public function getStatus()
  413.     {
  414.         return $this->status;
  415.     }
  416.     /**
  417.      * Set admin_notes
  418.      *
  419.      * @param text $adminNotes
  420.      *
  421.      * @return self
  422.      */
  423.     public function setAdminNotes($adminNotes)
  424.     {
  425.         $this->admin_notes $adminNotes;
  426.         return $this;
  427.     }
  428.     /**
  429.      * Get admin_notes
  430.      *
  431.      * @return text
  432.      */
  433.     public function getAdminNotes()
  434.     {
  435.         return $this->admin_notes;
  436.     }
  437.     /**
  438.      * Set admin_notes_cust
  439.      *
  440.      * @param text $adminNotesCust
  441.      *
  442.      * @return self
  443.      */
  444.     public function setAdminNotesCust($adminNotesCust)
  445.     {
  446.         $this->admin_notes_cust $adminNotesCust;
  447.         return $this;
  448.     }
  449.     /**
  450.      * Get admin_notes_cust
  451.      *
  452.      * @return text
  453.      */
  454.     public function getAdminNotesCust()
  455.     {
  456.         return $this->admin_notes_cust;
  457.     }
  458.     /**
  459.      * Set customer_notes
  460.      *
  461.      * @param text $customerNotes
  462.      *
  463.      * @return self
  464.      */
  465.     public function setCustomerNotes($customerNotes)
  466.     {
  467.         $this->customer_notes $customerNotes;
  468.         return $this;
  469.     }
  470.     /**
  471.      * Get customer_notes
  472.      *
  473.      * @return text
  474.      */
  475.     public function getCustomerNotes()
  476.     {
  477.         return $this->customer_notes;
  478.     }
  479.     /**
  480.      * Set product
  481.      *
  482.      * @param Product $product
  483.      *
  484.      * @return self
  485.      */
  486.     public function setProduct(Product $product null)
  487.     {
  488.         $this->product $product;
  489.         return $this;
  490.     }
  491.     /**
  492.      * Get product
  493.      *
  494.      * @return Product
  495.      */
  496.     public function getProduct()
  497.     {
  498.         return $this->product;
  499.     }
  500.     /**
  501.      * Set profile
  502.      *
  503.      * @param Profile $profile
  504.      *
  505.      * @return self
  506.      */
  507.     public function setProfile(Profile $profile null)
  508.     {
  509.         $this->profile $profile;
  510.         return $this;
  511.     }
  512.     /**
  513.      * Get profile
  514.      *
  515.      * @return Profile
  516.      */
  517.     public function getProfile()
  518.     {
  519.         return $this->profile;
  520.     }
  521.     /**
  522.      * Get net ProductPrice
  523.      *
  524.      * @return float
  525.      */
  526.     public function getNetProductPrice()
  527.     {
  528.         return Price::getInstance()->apply($this'getProductPrice', [], 'net');
  529.     }
  530.     /**
  531.      * Get net OfferPrice
  532.      *
  533.      * @return float
  534.      */
  535.     public function getNetOfferPrice()
  536.     {
  537.         return Price::getInstance()->apply($this'getOfferPrice', [], 'net');
  538.     }
  539. }