*/ protected $parts; /** * @param Context|\WC_Coupon $context * @param null $deprecated */ public function __construct($couponOrContext, $deprecated = null) { $this->context = adp_context(); $this->coupon = $couponOrContext instanceof \WC_Coupon ? $couponOrContext : $deprecated; $this->parts = array(); $this->fetchData(); } public function withContext(Context $context) { $this->context = $context; } protected function fetchData() { $adpMeta = $this->coupon->get_meta(self::KEY_ADP, true); $this->parts = isset($adpMeta[self::KEY_ADP_PARTS]) ? $adpMeta[self::KEY_ADP_PARTS] : array(); } /** * @return array */ public function getParts() { return $this->parts; } /** * @param array $parts */ public function setParts($parts) { $this->parts = array(); foreach ($parts as $part) { if ($part instanceof CouponInterface) { $this->parts[] = $part; } } } public function updateCoupon() { $this->coupon->update_meta_data(self::KEY_ADP, array( self::KEY_ADP_PARTS => $this->parts, )); } }